Almaatla commited on
Commit
6e4356a
1 Parent(s): 7b37006

Update app.py

Browse files

Added Mistral models

Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -25,6 +25,17 @@ import pandas as pd
25
  import numpy as np
26
  from openai import OpenAI
27
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  tokenizer = tiktoken.encoding_for_model("gpt-3.5-turbo")
30
 
@@ -37,7 +48,7 @@ def tiktoken_len(text):
37
  return len(tokens)
38
 
39
  text_splitter = RecursiveCharacterTextSplitter(
40
- chunk_size=600,
41
  chunk_overlap=200,
42
  length_function=tiktoken_len,
43
  separators=["\n\n", "\n", " ", ""]
@@ -415,9 +426,11 @@ def ask_gpt(query, apikey,history,ui_session_id):
415
 
416
  #new api query format
417
  def gpt_answer(api_key, query, model="gpt-3.5-turbo-1106", system_prompt="Use the provided References to answer the user Question. If the provided document do not contain the elements to answer the user question, just say 'No information.'."):
418
- client = OpenAI(
419
- api_key=api_key,
420
- )
 
 
421
 
422
  chat_completion = client.chat.completions.create(
423
  messages=[
@@ -430,6 +443,7 @@ def gpt_answer(api_key, query, model="gpt-3.5-turbo-1106", system_prompt="Use th
430
  return chat_completion.choices[0].message.content
431
 
432
 
 
433
  def add_line_breaks(input_string, line_length=100):
434
  lines = []
435
  to_break=input_string.split("\n---\n[Sources]")[0]
@@ -497,7 +511,7 @@ with gr.Blocks() as demo:
497
  gr.Markdown("Upload your documents and question them.")
498
  with gr.Accordion("Open to enter your API key", open=False):
499
  apikey_input = gr.Textbox(placeholder="Type here your OpenAI API key to use Summarization and Q&A", label="OpenAI API Key",type='password')
500
- dd_model = gr.Dropdown(["gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4-1106-preview", "gpt-4", "gpt-4-32k"], value="gpt-3.5-turbo-1106", label='List of models', allow_custom_value=True, scale=1)
501
 
502
  with gr.Tab("Upload PDF & TXT"):
503
  with gr.Accordion("Get files from the web", open=False):
 
25
  import numpy as np
26
  from openai import OpenAI
27
 
28
+ from mistralai.client import MistralClient
29
+ from mistralai.models.chat_completion import ChatMessage
30
+
31
+ MODEL_LIST = [
32
+ "mistral-tiny",
33
+ "mistral-small",
34
+ "mistral-medium",
35
+ ]
36
+ DEFAULT_MODEL = "mistral-small"
37
+ DEFAULT_TEMPERATURE = 0.7
38
+
39
 
40
  tokenizer = tiktoken.encoding_for_model("gpt-3.5-turbo")
41
 
 
48
  return len(tokens)
49
 
50
  text_splitter = RecursiveCharacterTextSplitter(
51
+ chunk_size=512,
52
  chunk_overlap=200,
53
  length_function=tiktoken_len,
54
  separators=["\n\n", "\n", " ", ""]
 
426
 
427
  #new api query format
428
  def gpt_answer(api_key, query, model="gpt-3.5-turbo-1106", system_prompt="Use the provided References to answer the user Question. If the provided document do not contain the elements to answer the user question, just say 'No information.'."):
429
+ if 'gpt' in model:
430
+ client = OpenAI( api_key=api_key)
431
+
432
+ if 'mistral' in model:
433
+ client = MistralClient(api_key=api_key)
434
 
435
  chat_completion = client.chat.completions.create(
436
  messages=[
 
443
  return chat_completion.choices[0].message.content
444
 
445
 
446
+
447
  def add_line_breaks(input_string, line_length=100):
448
  lines = []
449
  to_break=input_string.split("\n---\n[Sources]")[0]
 
511
  gr.Markdown("Upload your documents and question them.")
512
  with gr.Accordion("Open to enter your API key", open=False):
513
  apikey_input = gr.Textbox(placeholder="Type here your OpenAI API key to use Summarization and Q&A", label="OpenAI API Key",type='password')
514
+ dd_model = gr.Dropdown(["gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-4-1106-preview", "gpt-4", "gpt-4-32k"]+ MODEL_LIST, value="gpt-3.5-turbo-1106", label='List of models', allow_custom_value=True, scale=1)
515
 
516
  with gr.Tab("Upload PDF & TXT"):
517
  with gr.Accordion("Get files from the web", open=False):