Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Jan 10, 2025
1 parent 57a7e00 commit b5d4177
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions examples/openai_assistant/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python3

#!/usr/bin/env python3
from openai import AsyncOpenAI
from openai.types.beta.assistant_stream_event import ThreadMessageInProgress
from openai.types.beta.threads import MessageDeltaEvent, TextDeltaBlock
Expand All @@ -11,27 +10,28 @@

@ui.page('/')
async def main():

assistant = await client.beta.assistants.create(
name='NiceGUI Assistant',
instructions='''
You are a personal assistant for NiceGUI developers.
Your sole focus is to help with questions about the NiceGUI framework.
You are precise and concise. Stay on the topic. Very short answers are preferred but always be friendly and polite.
You are precise and concise.
Stay on the topic.
Very short answers are preferred, but always be friendly and polite.
''',
tools=[{'type': 'code_interpreter'}],
model='gpt-4o-mini',
)

thread = await client.beta.threads.create()

async def send():
async def send() -> None:
response.content = ''
spinner = ui.spinner(size='5em', type='comment').classes('mx-auto')
await client.beta.threads.messages.create(
thread_id=thread.id,
role='user',
content=question.value
content=question.value,
)
stream = await client.beta.threads.runs.create(
assistant_id=assistant.id,
Expand All @@ -49,7 +49,7 @@ async def send():
continue
response.content += content.text.value

with ui.column().classes('mx-auto w-full max-w-xl mt-16'):
with ui.column().classes('mx-auto w-full max-w-xl my-16'):
ui.label('NiceGUI Assistant').classes('text-2xl font-bold mx-auto')
question = ui.input(value='Why does NiceGUI use async/await?') \
.classes('w-full self-center mt-4').props('hint="Ask your question" dense') \
Expand Down
2 changes: 1 addition & 1 deletion website/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ def __post_init__(self) -> None:
Example('NGINX HTTPS', 'Use NGINX to serve a NiceGUI app with HTTPS'),
Example('Node Module Integration', 'Use NPM to add dependencies to a NiceGUI app'),
Example('Signature Pad', 'A custom element based on [signature_pad](https://www.npmjs.com/package/signature_pad'),
Example('OpenAI Assistant', 'Using OpenAI\'s Assistant API with async/await'),
Example('OpenAI Assistant', "Using OpenAI's Assistant API with async/await"),
]

0 comments on commit b5d4177

Please sign in to comment.