Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imrpove example for RAG #45

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading