LangChain
Use Odin v1 as a LangChain chat model in Python or JavaScript.
LangChain's OpenAI chat model works with InterOdin once it is pointed at https://api.interodin.com/v1. See Not supported for what the OpenAI-compatible API doesn't accept. Built-in (hosted) tools are removed from the request; only your own tools run.
Python
pip install langchain-openaiimport os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="odin-v1",
base_url="https://api.interodin.com/v1",
api_key=os.environ["INTERODIN_API_KEY"],
)
print(llm.invoke("Name three Norse gods.").content)
for chunk in llm.stream("Write a haiku about Odin."):
print(chunk.content, end="", flush=True)Tools and structured output
import os
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from pydantic import BaseModel
llm = ChatOpenAI(model="odin-v1", base_url="https://api.interodin.com/v1", api_key=os.environ["INTERODIN_API_KEY"])
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"14°C in {city}"
reply = llm.bind_tools([get_weather]).invoke("What is the weather in Cluj?")
print(reply.tool_calls)
class Person(BaseModel):
name: str
age: int
person = llm.with_structured_output(Person).invoke("Extract the person: Ana is 31.")
print(person)With the Anthropic integration
If your code uses langchain-anthropic, set its base URL to the origin, without /v1:
import os
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(
model="odin-v1",
base_url="https://api.interodin.com",
api_key=os.environ["INTERODIN_API_KEY"],
max_tokens=1024,
)
print(llm.invoke("Name three Norse gods.").content)JavaScript / TypeScript
npm install @langchain/openai @langchain/coreimport { ChatOpenAI } from '@langchain/openai'
const llm = new ChatOpenAI({
model: 'odin-v1',
apiKey: process.env.INTERODIN_API_KEY,
configuration: { baseURL: 'https://api.interodin.com/v1' },
})
const reply = await llm.invoke('Name three Norse gods.')
console.log(reply.content)
for await (const chunk of await llm.stream('Write a haiku about Odin.')) {
process.stdout.write(String(chunk.content))
}Token usage is reported in response_metadata on each reply. In the console it shows up per API key.