mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-17 21:25:46 +02:00
6.6 KiB
6.6 KiB
In [16]:
from langgraph_sdk import get_client
client = get_client()In [14]:
# First, let's check what valid configuration can be
# We can do this by getting the default assistant
# There should always be a default assistant with no configuration
assistants = await client.assistants.search()
assistants = [a for a in assistants if not a["config"]]
base_assistant = assistants[0]In [17]:
# We can now call `.get_schemas` to get schemas associated with this graph
schemas = await client.assistants.get_schemas(
assistant_id=base_assistant["assistant_id"]
)
# There are multiple types of schemas
# We can get the `config_schema` to look at the the configurable parameters
schemas["config_schema"]["definitions"]["Configurable"]["properties"]Out [17]:
{'model_name': {'title': 'Model Name',
'enum': ['anthropic', 'openai'],
'type': 'string'}}In [18]:
assistant = await client.assistants.create(
graph_id="agent", config={"configurable": {"model_name": "openai"}}
)In [20]:
assistantOut [20]:
{'assistant_id': '40a3a2bf-5319-4fae-a2ac-05e075615cdc',
'graph_id': 'agent',
'config': {'configurable': {'model_name': 'openai'}},
'created_at': '2024-06-05T23:12:30.519458+00:00',
'updated_at': '2024-06-05T23:12:30.519458+00:00',
'metadata': {}}In [21]:
thread = await client.threads.create()
input = {"messages": [{"role": "user", "content": "who made you?"}]}
async for event in client.runs.stream(
thread["thread_id"], assistant["assistant_id"], input=input
):
print(event)StreamPart(event='metadata', data={'run_id': '1ef23911-c23b-6d8c-b1dc-94bb982ca7b1'})
StreamPart(event='values', data={'messages': [{'role': 'user', 'content': 'who made you?'}]})
StreamPart(event='values', data={'messages': [{'content': 'who made you?', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'human', 'name': None, 'id': 'ed93c1c9-80d6-4f2b-a048-ef859ea533f9', 'example': False}, {'content': 'I was created by OpenAI, a research organization focused on developing and advancing artificial intelligence technology.', 'additional_kwargs': {}, 'response_metadata': {'finish_reason': 'stop'}, 'type': 'ai', 'name': None, 'id': 'run-6560cd65-5c9c-434b-8835-0baadc684760', 'example': False, 'tool_calls': [], 'invalid_tool_calls': [], 'usage_metadata': None}]})
StreamPart(event='end', data=None)