Langchain Usage Instructions
Interface Information
| Item | Value |
|---|---|
| Base URL (for LangChain) | https://api-ai.gitcode.com/v1 |
| Full Chat Path | POST https://api-ai.gitcode.com/v1/chat/completions |
| Model ID | deepseek-ai/DeepSeek-R1 |
| Protocol | JSON compatible with OpenAI Chat Completions |
ChatOpenAIwill automatically append/chat/completionstobase_url, do not setbase_urlas a full URL including/chat/completions.
Authentication
Usually it is Bearer Token (please refer to the platform's actual instructions):
Authorization: Bearer <AtomGit Access Token>
Content-Type: application/json
Request Body (same as OpenAI, example)
{
"model": "deepseek-ai/DeepSeek-R1",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Introduce LangChain in one sentence." }
],
"temperature": 0.7,
"max_tokens": 1024,
"stream": true
}
Optional fields (if supported by the server): top_p, stop, presence_penalty, frequency_penalty, etc.
Environment Setup
pip install langchain-openai
Example One: Streaming Chat
import os
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage
llm = ChatOpenAI(
model="deepseek-ai/DeepSeek-R1",
base_url="https://api-ai.gitcode.com/v1",
api_key=os.environ["ATOMGit_AI_API_KEY"], # AtomGit Access Token (API key)
temperature=0.7,
streaming=True,
)
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="Introduce LangChain in one sentence."),
]
for chunk in llm.stream(messages):
if chunk.content:
print(chunk.content, end="", flush=True)
print()
Notes
base_url: Ends with/v1, do not repeat/chat/completions.model: Must match the platform's model:deepseek-ai/DeepSeek-R1.- Access Token: Do not hardcode the AtomGit access token into the repository, use environment variables (such as
ATOMGit_AI_API_KEY) or include it inAuthorization: Bearer <AtomGit Access Token>.