Skip to content

Commit

Permalink
Merge pull request #85 from ks6088ts-labs/cosmetic-changes
Browse files Browse the repository at this point in the history
Cosmetic changes
  • Loading branch information
ks6088ts authored Jun 8, 2024
2 parents 1ce48e8 + 1222837 commit c1c1ce5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- [FastAPI > Extending OpenAPI](https://fastapi.tiangolo.com/how-to/extending-openapi/)
- [Get started with Azure Blob Storage and Python](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-python-get-started?tabs=sas-token)
- [FastAPI で実装した様々なエンドポイントのテストを書く(フォームデータの送信、クッキーの確認、ファイルのアップロード等)](https://qiita.com/kurumaebi65/items/d5cda239ef601f4c36ef#%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89)
- [LangChainのstreaming出力で苦労している人おる](https://qiita.com/numekudi/items/4a9e7728ac10c3515ed1)
- [LangChain の streaming 出力で苦労している人おる](https://qiita.com/numekudi/items/4a9e7728ac10c3515ed1)
- [Quickstart: Azure Queue Storage client library for Python](https://learn.microsoft.com/en-us/azure/storage/queues/storage-quickstart-queues-python?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
- [Azure Event Grid client library for Python - version 4.19.0](https://learn.microsoft.com/en-us/python/api/overview/azure/eventgrid-readme?view=azure-python)
- [Azure Event Grid Client Library Python Samples](https://learn.microsoft.com/en-us/samples/azure/azure-sdk-for-python/eventgrid-samples/)
Expand All @@ -39,7 +39,8 @@
- [Streamlit API cheat sheet](https://docs.streamlit.io/develop/quick-reference/cheat-sheet)
- [Streamlit > Display progress and status](https://docs.streamlit.io/develop/api-reference/status)
- [streamlit-audiorecorder](https://github.com/theevann/streamlit-audiorecorder)
- [Build a basic LLM chat app](https://docs.streamlit.io/develop/tutorials/llms/build-conversational-apps)
- [Streamlit > Build a basic LLM chat app](https://docs.streamlit.io/develop/tutorials/llms/build-conversational-apps)
- [OpenAI の新しい API を Streamlit で使ってみた](https://qiita.com/papasim824/items/5a3bee4cc3915d5ae177)
- [aiohttp > Installing all speedups in one command](https://docs.aiohttp.org/en/stable/#installing-all-speedups-in-one-command)
- [Python & aiohttp: How to upload files to a remote server](https://www.slingacademy.com/article/python-aiohttp-how-to-upload-files-to-a-remote-server/)

Expand Down
24 changes: 16 additions & 8 deletions frontend/solutions/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ def start(
with st.chat_message("user"):
st.markdown(prompt)

with st.chat_message("assistant"):
stream = client.chat.completions.create(
model=getenv("AZURE_OPENAI_GPT_MODEL"),
messages=[{"role": m["role"], "content": m["content"]} for m in st.session_state.messages],
stream=True,
)
response = st.write_stream(stream)
st.session_state.messages.append({"role": "assistant", "content": response})
response = client.chat.completions.create(
model=getenv("AZURE_OPENAI_GPT_MODEL"),
messages=[{"role": m["role"], "content": m["content"]} for m in st.session_state.messages],
stream=True,
)
with st.chat_message("assistant", avatar="assistant"):
placeholder = st.empty()
assistant_text = ""
for chunk in response:
if len(chunk.choices) <= 0:
continue
content = chunk.choices[0].delta.content
if content:
assistant_text += content
placeholder.write(assistant_text)
st.session_state.messages.append({"role": "assistant", "content": assistant_text})
9 changes: 3 additions & 6 deletions frontend/solutions/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ async def chat_completions_post(
response = await client.azure_openai.chat_completions.post(
ChatCompletionRequest(
content=prompt,
stream=False,
),
)
return response.content
Expand All @@ -42,14 +41,12 @@ def start(
logger.setLevel(log_level)
logger.debug(f"set log level to {log_level}")

st.write("Misc solution")

# GET
st.write("Get OpenAPI spec")
if st.button("GET"):
logger.info("Fetching data from backend...")
try:
with st.spinner("Calling API..."):
response = asyncio.run(http_get(url=urljoin(base=backend_url, url="")))
response = asyncio.run(http_get(url=urljoin(base=urljoin(backend_url, "openapi.json"), url="")))
st.write(response)
logger.info("Data fetched successfully.")
except Exception as e:
Expand All @@ -58,7 +55,7 @@ def start(

st.write("---")

# POST
st.write("Call Azure OpenAI API")
prompt = st.text_input(
label="Prompt",
value="Hello",
Expand Down

0 comments on commit c1c1ce5

Please sign in to comment.