mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-20 22:52:29 +02:00
* Create Deploy docs. * Add LangGraph CLI docs. * Update API concepts page. * Create quick start page. * first draft (#695) * first draft * fmt * fmt * Revert "fmt" This reverts commite599030ab5. * Revert "fmt" This reverts commitec8fca977e. * var change * import lint * changed locations * second draft * fmt * Revert "fmt" This reverts commit68a1c5c872. * double texting lint * concepts (#704) * concepts * python sdk * docs structure * fmt * fmt * Small touch ups, rename Hosted LangGraph API to LangGraph Cloud. (#724) * Fix small typos. * Fix broken links in quick start page. * Add LangGraph Cloud reference docs. --------- Co-authored-by: Isaac Francisco <78627776+isahers1@users.noreply.github.com>
6.7 KiB
6.7 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)
In [ ]: