From 190202abf1e96c0a6ac471e84a7446b3bcd462f0 Mon Sep 17 00:00:00 2001 From: linustseng Date: Fri, 10 May 2024 07:06:30 +0000 Subject: [PATCH 1/3] Main --- Chatbot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chatbot.py b/Chatbot.py index 0a4f2df45..e7ee726a2 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -7,7 +7,7 @@ "[View the source code](https://github.com/streamlit/llm-examples/blob/main/Chatbot.py)" "[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1)" -st.title("πŸ’¬ Chatbot") +st.title("πŸ’¬ AIA Chatbot") st.caption("πŸš€ A Streamlit chatbot powered by OpenAI") if "messages" not in st.session_state: st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}] From a8036a9298e488eb47791f54f53c84fc8374b6aa Mon Sep 17 00:00:00 2001 From: linustseng Date: Fri, 10 May 2024 07:36:52 +0000 Subject: [PATCH 2/3] add to ollama --- .vscode/settings.json | 5 +++++ Chatbot.py | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..b242572ef --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ] +} \ No newline at end of file diff --git a/Chatbot.py b/Chatbot.py index e7ee726a2..ce62b6af4 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -1,29 +1,35 @@ -from openai import OpenAI +from langchain.chains import ConversationalRetrievalChain +from langchain.chains.llm import LLMChain +from langchain.schema import Document +from langchain_community.llms import Ollama + import streamlit as st with st.sidebar: + st.text_input("choose version") +""" openai_api_key = st.text_input("OpenAI API Key", key="chatbot_api_key", type="password") "[Get an OpenAI API key](https://platform.openai.com/account/api-keys)" "[View the source code](https://github.com/streamlit/llm-examples/blob/main/Chatbot.py)" "[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1)" +""" st.title("πŸ’¬ AIA Chatbot") -st.caption("πŸš€ A Streamlit chatbot powered by OpenAI") +st.caption("πŸš€ AIA θͺ²η¨‹ζŸ₯θ©’ζ©Ÿε™¨δΊΊ") if "messages" not in st.session_state: st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}] for msg in st.session_state.messages: st.chat_message(msg["role"]).write(msg["content"]) +llm = Ollama(model="llama3", base_url="http://3ece-140-109-17-42.ngrok-free.app") + if prompt := st.chat_input(): - if not openai_api_key: - st.info("Please add your OpenAI API key to continue.") - st.stop() - client = OpenAI(api_key=openai_api_key) st.session_state.messages.append({"role": "user", "content": prompt}) st.chat_message("user").write(prompt) - response = client.chat.completions.create(model="gpt-3.5-turbo", messages=st.session_state.messages) - msg = response.choices[0].message.content + response = llm.invoke(st.session_state.messages) + #msg = response.choices[0].message.content + msg = response st.session_state.messages.append({"role": "assistant", "content": msg}) st.chat_message("assistant").write(msg) From b55cae1160d4df6294ed331752fcfff4432d556b Mon Sep 17 00:00:00 2001 From: linustseng Date: Fri, 10 May 2024 07:38:53 +0000 Subject: [PATCH 3/3] remove needless text --- Chatbot.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Chatbot.py b/Chatbot.py index ce62b6af4..3b8200580 100644 --- a/Chatbot.py +++ b/Chatbot.py @@ -7,12 +7,11 @@ with st.sidebar: st.text_input("choose version") -""" - openai_api_key = st.text_input("OpenAI API Key", key="chatbot_api_key", type="password") - "[Get an OpenAI API key](https://platform.openai.com/account/api-keys)" - "[View the source code](https://github.com/streamlit/llm-examples/blob/main/Chatbot.py)" - "[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1)" -""" + +# openai_api_key = st.text_input("OpenAI API Key", key="chatbot_api_key", type="password") +# "[Get an OpenAI API key](https://platform.openai.com/account/api-keys)" +# "[View the source code](https://github.com/streamlit/llm-examples/blob/main/Chatbot.py)" +# "[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1)" st.title("πŸ’¬ AIA Chatbot") st.caption("πŸš€ AIA θͺ²η¨‹ζŸ₯θ©’ζ©Ÿε™¨δΊΊ")