@@ -42,68 +42,27 @@ Now open up a new terminal and copy the following script into a file named `demo
4242# This source code is licensed under the terms described in the LICENSE file in
4343# the root directory of this source tree.
4444
45- from llama_stack_client import Agent, AgentEventLogger, RAGDocument, LlamaStackClient
4645
47- vector_db_id = " my_demo_vector_db "
48- client = LlamaStackClient( base_url = " http://localhost:8321 " )
46+ import io, requests
47+ from openai import OpenAI
4948
50- models = client.models.list()
49+ url= " https://www.paulgraham.com/greatwork.html"
50+ client = OpenAI(base_url = " http://localhost:8321/v1/" , api_key = " none" )
5151
52- # Select the first LLM and first embedding models
53- model_id = next (m for m in models if m.model_type == " llm" ).identifier
54- embedding_model_id = (
55- em := next (m for m in models if m.model_type == " embedding" )
56- ).identifier
57- embedding_dimension = em.metadata[" embedding_dimension" ]
52+ vs = client.vector_stores.create()
53+ response = requests.get(url)
54+ pseudo_file = io.BytesIO(str (response.content).encode(' utf-8' ))
55+ uploaded_file = client.files.create(file = (url, pseudo_file, " text/html" ), purpose = " assistants" )
56+ client.vector_stores.files.create(vector_store_id = vs.id, file_id = uploaded_file.id)
5857
59- vector_db = client.vector_dbs.register(
60- vector_db_id = vector_db_id,
61- embedding_model = embedding_model_id,
62- embedding_dimension = embedding_dimension,
63- provider_id = " faiss" ,
64- )
65- vector_db_id = vector_db.identifier
66- source = " https://www.paulgraham.com/greatwork.html"
67- print (" rag_tool> Ingesting document:" , source)
68- document = RAGDocument(
69- document_id = " document_1" ,
70- content = source,
71- mime_type = " text/html" ,
72- metadata = {},
73- )
74- client.tool_runtime.rag_tool.insert(
75- documents = [document],
76- vector_db_id = vector_db_id,
77- chunk_size_in_tokens = 100 ,
78- )
79- agent = Agent(
80- client,
81- model = model_id,
82- instructions = " You are a helpful assistant" ,
83- tools = [
84- {
85- " name" : " builtin::rag/knowledge_search" ,
86- " args" : {" vector_db_ids" : [vector_db_id]},
87- }
88- ],
89- )
90-
91- prompt = " How do you do great work?"
92- print (" prompt>" , prompt)
93-
94- use_stream = True
95- response = agent.create_turn(
96- messages = [{" role" : " user" , " content" : prompt}],
97- session_id = agent.create_session(" rag_session" ),
98- stream = use_stream,
58+ resp = client.responses.create(
59+ model = " openai/gpt-4o" ,
60+ input = " How do you do great work? Use the existing knowledge_search tool." ,
61+ tools = [{" type" : " file_search" , " vector_store_ids" : [vs.id]}],
62+ include = [" file_search_call.results" ],
9963)
10064
101- # Only call `AgentEventLogger().log(response)` for streaming responses.
102- if use_stream:
103- for log in AgentEventLogger().log(response):
104- log.print()
105- else :
106- print (response)
65+ print (resp)
10766```
10867We will use ` uv ` to run the script
10968```
0 commit comments