Skip to content

Commit 7fb93d1

Browse files
committed
Ollama support for openai and langgraph examples
1 parent 85b4868 commit 7fb93d1

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

examples/langgraph_agent.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ def play_song_on_apple(song: str):
4343
elif API_HOST == "github":
4444
model = ChatOpenAI(model=os.getenv("GITHUB_MODEL", "gpt-4o"), base_url="https://models.inference.ai.azure.com", api_key=os.environ["GITHUB_TOKEN"])
4545
elif API_HOST == "ollama":
46-
model = ChatOpenAI(model=os.environ["OLLAMA_MODEL"], base_url=os.environ["OLLAMA_ENDPOINT"], api_key="none")
46+
model = ChatOpenAI(model=os.environ["OLLAMA_MODEL"], base_url=os.environ.get("OLLAMA_ENDPOINT", "http://localhost:11434/v1"), api_key="none")
4747

4848
model = model.bind_tools(tools, parallel_tool_calls=False)
4949

50-
# Define nodes and conditional edges
51-
5250

5351
# Define the function that determines whether to continue or not
5452
def should_continue(state):

examples/openai_agents_tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
azure_ad_token_provider=token_provider,
3232
)
3333
MODEL_NAME = os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT"]
34+
elif API_HOST == "ollama":
35+
client = openai.AsyncOpenAI(base_url=os.environ.get("OLLAMA_ENDPOINT", "http://localhost:11434/v1"), api_key="none")
36+
MODEL_NAME = os.environ["OLLAMA_MODEL"]
3437

3538

3639
@function_tool

0 commit comments

Comments
 (0)