|
1 |
| -from langchain_anthropic import ChatAnthropic |
2 | 1 | from langchain_core.messages import HumanMessage, SystemMessage
|
3 |
| -from langchain_openai import ChatOpenAI |
4 | 2 | from langgraph.graph import START, StateGraph, END
|
| 3 | +from uipath_langchain.chat import UiPathChat |
5 | 4 | from pydantic import BaseModel
|
6 |
| -import os |
| 5 | + |
| 6 | +llm = UiPathChat(model="gpt-4o-mini-2024-07-18") |
| 7 | + |
7 | 8 |
|
8 | 9 | class GraphState(BaseModel):
|
9 | 10 | topic: str
|
10 | 11 |
|
| 12 | + |
11 | 13 | class GraphOutput(BaseModel):
|
12 | 14 | report: str
|
13 | 15 |
|
14 |
| -async def generate_report(state: GraphState) -> GraphOutput: |
15 |
| - if os.getenv("ANTHROPIC_API_KEY"): |
16 |
| - llm_model = ChatAnthropic(model="claude-3-5-sonnet-latest") |
17 |
| - elif os.getenv("OPENAI_API_KEY"): |
18 |
| - llm_model = ChatOpenAI(model="gpt-4o-mini", temperature=0) |
19 |
| - else: |
20 |
| - raise Exception("Missing API Key. Please define either ANTHROPIC_API_KEY or OPENAI_API_KEY.") |
21 | 16 |
|
| 17 | +async def generate_report(state: GraphState) -> GraphOutput: |
22 | 18 | system_prompt = "You are a report generator. Please provide a brief report based on the given topic."
|
23 |
| - output = await llm_model.ainvoke([SystemMessage(system_prompt), HumanMessage(state.topic)]) |
| 19 | + output = await llm.ainvoke( |
| 20 | + [SystemMessage(system_prompt), HumanMessage(state.topic)] |
| 21 | + ) |
24 | 22 | return GraphOutput(report=output.content)
|
25 | 23 |
|
| 24 | + |
26 | 25 | builder = StateGraph(GraphState, output=GraphOutput)
|
27 | 26 |
|
28 | 27 | builder.add_node("generate_report", generate_report)
|
|
0 commit comments