okoliechykwuka commited on
Commit
1c8cb74
1 Parent(s): 7f048da

modified chatboot

Browse files
Files changed (1) hide show
  1. chatbot.py +21 -12
chatbot.py CHANGED
@@ -7,9 +7,12 @@ from langchain.prompts import (
7
  from langchain.chains import ConversationChain
8
  from langchain.chat_models import ChatOpenAI
9
  from langchain.memory import ConversationBufferMemory
 
10
  import panel as pn
11
  import os
12
 
 
 
13
  panels = [] # collect display
14
 
15
  pn.extension('texteditor', template="bootstrap", sizing_mode='stretch_width')
@@ -56,18 +59,24 @@ def collect_messages(_):
56
  pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'})))
57
 
58
  return pn.Column(*panels)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
- #layout
61
- interactive_conversation = pn.bind(collect_messages, button_conversation)
62
- pn.Column(
63
- pn.pane.Markdown("""
64
- ## \U0001F60A! A friendly Conversational AI Chatbot
65
- 1) Enter OpenAI API key. This costs $. Set up billing at [OpenAI](https://platform.openai.com/account).
66
- """
67
- ),
68
- pn.Row(inp,spacer,openaikey),
69
- pn.Row(button_conversation, width=200, margin=(5,150)),
70
- pn.panel(interactive_conversation, loading_indicator=True, height=200),
71
- ).servable()
72
 
73
 
 
7
  from langchain.chains import ConversationChain
8
  from langchain.chat_models import ChatOpenAI
9
  from langchain.memory import ConversationBufferMemory
10
+ import openai
11
  import panel as pn
12
  import os
13
 
14
+ os.environ["LANGCHAIN_TRACING"] = "true"
15
+
16
  panels = [] # collect display
17
 
18
  pn.extension('texteditor', template="bootstrap", sizing_mode='stretch_width')
 
59
  pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'})))
60
 
61
  return pn.Column(*panels)
62
+ try:
63
+ #layout
64
+ interactive_conversation = pn.bind(collect_messages, button_conversation)
65
+ pn.Column(
66
+ pn.pane.Markdown("""
67
+ ## \U0001F60A! A friendly Conversational AI Chatbot
68
+ 1) Enter OpenAI API key. This costs $. Set up billing at [OpenAI](https://platform.openai.com/account).
69
+ """
70
+ ),
71
+ pn.Row(inp,spacer,openaikey),
72
+ pn.Row(button_conversation, width=200, margin=(5,150)),
73
+ pn.panel(interactive_conversation, loading_indicator=True, height=200),
74
+ ).servable()
75
+ except openai.error.AuthenticationError:
76
+ # Handle the AuthenticationError
77
+ print("Authentication error: Invalid API key or insufficient permissions.")
78
+ # Perform any necessary actions, such as displaying an error message or exiting the program
79
+
80
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82