Skip to content

Commit

Permalink
Imrpove example for RAG
Browse files Browse the repository at this point in the history
  • Loading branch information
vhaldemar committed Dec 16, 2024
1 parent fcf8118 commit c9be1bb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
29 changes: 20 additions & 9 deletions examples/async/assistants/assistant_with_search_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,26 @@ async def main() -> None:
assistant = await sdk.assistants.create('yandexgpt', tools=[tool])
thread = await sdk.threads.create()

for search_query in (
local_path('search_query.txt').read_text().splitlines()[0],
"Cколько пошлина в Анталье"
):
await thread.write(search_query)
run = await assistant.run(thread)
result = await run
print('Question', search_query)
print('Answer:', result.text)
search_query = local_path('search_query.txt').read_text().splitlines()[0]
await thread.write(search_query)
run = await assistant.run(thread)

# poll_inteval is 0.5s by default, but you could lower it to optimize
# wait time
result = await run.wait(poll_interval=0.05)
print('Question:', search_query)
print('Answer:', result.text)

search_query = "Cколько пошлина в Анталье"
await thread.write(search_query)

# You could also use run_stream method to start gettig response parts
# as soon it will be generated
run = await assistant.run_stream(thread)
print('Question:', search_query)
async for event in run:
print("Answer part:", event.text)
print("Answer status:", event.status)

await search_index.delete()
await thread.delete()
Expand Down
29 changes: 20 additions & 9 deletions examples/sync/assistants/assistant_with_search_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@ def main() -> None:
assistant = sdk.assistants.create('yandexgpt', tools=[tool])
thread = sdk.threads.create()

for search_query in (
local_path('search_query.txt').read_text().splitlines()[0],
"Cколько пошлина в Анталье"
):
thread.write(search_query)
run = assistant.run(thread)
result = run.wait()
print('Question', search_query)
print('Answer:', result.text)
search_query = local_path('search_query.txt').read_text().splitlines()[0]
thread.write(search_query)
run = assistant.run(thread)

# poll_inteval is 0.5s by default, but you could lower it to optimize
# wait time
result = run.wait(poll_interval=0.05)
print('Question:', search_query)
print('Answer:', result.text)

search_query = "Cколько пошлина в Анталье"
thread.write(search_query)

# You could also use run_stream method to start gettig response parts
# as soon it will be generated
run = assistant.run_stream(thread)
print('Question:', search_query)
for event in run:
print("Answer part:", event.text)
print("Answer status:", event.status)

search_index.delete()
thread.delete()
Expand Down

0 comments on commit c9be1bb

Please sign in to comment.