ogegadavis254 commited on
Commit
0634989
·
verified ·
1 Parent(s): a9c7401

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -1,21 +1,16 @@
1
  """
2
  Simple Chatbot
3
- @author: Nigel Gebodh
4
- @email: nigel.gebodh@gmail.com
5
  """
6
 
7
  import streamlit as st
8
- from openai import OpenAI
9
  import os
10
  from dotenv import load_dotenv
11
 
12
  load_dotenv()
13
 
14
  # Initialize the client
15
- client = OpenAI(
16
- base_url="https://api-inference.huggingface.co/v1",
17
- api_key=os.environ.get('HUGGINGFACEHUB_API_TOKEN') # Replace with your token
18
- )
19
 
20
  model_link = "mistralai/Mistral-7B-Instruct-v0.2"
21
 
@@ -57,18 +52,16 @@ if prompt:
57
  # Display assistant response in chat message container
58
  with st.chat_message("assistant"):
59
  try:
60
- response = client.chat.completions.create(
61
- model=model_link,
62
- messages=[
63
- {"role": m["role"], "content": m["content"]}
64
- for m in st.session_state.messages
65
- ],
66
- temperature=temperature,
67
- max_tokens=3000
68
- )['choices'][0]['message']['content']
69
 
70
- st.markdown(response)
71
- st.session_state.messages.append({"role": "assistant", "content": response})
 
72
 
73
  except Exception as e:
74
  st.markdown("An error occurred. Please try again later.")
 
1
  """
2
  Simple Chatbot
 
 
3
  """
4
 
5
  import streamlit as st
6
+ import openai # Ensure you have the correct import
7
  import os
8
  from dotenv import load_dotenv
9
 
10
  load_dotenv()
11
 
12
  # Initialize the client
13
+ openai.api_key = os.environ.get('HUGGINGFACEHUB_API_TOKEN') # Replace with your token
 
 
 
14
 
15
  model_link = "mistralai/Mistral-7B-Instruct-v0.2"
16
 
 
52
  # Display assistant response in chat message container
53
  with st.chat_message("assistant"):
54
  try:
55
+ response = openai.Completion.create(
56
+ engine=model_link,
57
+ prompt=prompt,
58
+ max_tokens=3000,
59
+ temperature=temperature
60
+ )
 
 
 
61
 
62
+ response_content = response.choices[0].text.strip()
63
+ st.markdown(response_content)
64
+ st.session_state.messages.append({"role": "assistant", "content": response_content})
65
 
66
  except Exception as e:
67
  st.markdown("An error occurred. Please try again later.")