import os import openai import gradio as gr # openai.api_key = "sk-" # Replace with your key OPENAI_API_KEY=os.getenv('OPENAI_API_KEY') USER=os.getenv('USER') PASS=os.getenv('PASS') system_message = "\nYou are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information." title = "Llama2 70B Chatbot" description = """ This Space demonstrates model [Llama-2-70b-chat-hf](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) by Meta, a Llama 2 model with 70B parameters fine-tuned for chat instructions. This space is running on Inference Endpoints using text-generation-inference library. If you want to run your own service, you can also [deploy the model on Inference Endpoints](https://ui.endpoints.huggingface.co/). 🔎 For more details about the Llama 2 family of models and how to use them with `transformers`, take a look [at our blog post](https://huggingface.co/blog/llama2). 🔨 Looking for lighter chat model versions of Llama-v2? - 🐇 Check out the [7B Chat model demo](https://huggingface.co/spaces/huggingface-projects/llama-2-7b-chat). - 🦊 Check out the [13B Chat model demo](https://huggingface.co/spaces/huggingface-projects/llama-2-13b-chat). Note: As a derivate work of [Llama-2-70b-chat](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) by Meta, this demo is governed by the original [license](https://huggingface.co/spaces/ysharma/Explore_llamav2_with_TGI/blob/main/LICENSE.txt) and [acceptable use policy](https://huggingface.co/spaces/ysharma/Explore_llamav2_with_TGI/blob/main/USE_POLICY.md). """ css = """.toast-wrap { display: none !important } """ examples=[ 'Hello there! How are you doing?', 'Can you explain to me briefly what is Python programming language?', 'Explain the plot of Cinderella in a sentence.', 'How many hours does it take a man to eat a Helicopter?', "Write a 100-word article on 'Benefits of Open-Source in AI research'", ] def predict(message, history): history_openai_format = [] for human, assistant in history: history_openai_format.append({"role": "user", "content": human }) history_openai_format.append({"role": "assistant", "content":assistant}) history_openai_format.append({"role": "user", "content": message}) response = openai.ChatCompletion.create( model='gpt-3.5-turbo', messages= history_openai_format, temperature=1.0, stream=True ) gr.Blocks() : gr.ChatInterface(predict, title=title, description=description, css=css, examples=examples, cache_examples=True) gr.ChatInterface(predict).queue().launch(auth=(USER, PASS))