Spaces:
Runtime error
Runtime error
import argparse | |
import gradio as gr | |
from openai import OpenAI | |
CLIENT = OpenAI(api_key="dummy", base_url="http://34.125.92.207:8081/v1") | |
def http_bot(prompt, history): | |
# Convert history to the format expected by the OpenAI API | |
# messages = [{"role": "user" if item['is_user'] else "assistant", "content": item['content']} for item in history] | |
messages = [] | |
# Add the current prompt to the messages | |
prompt_final = f"""You are SEMIKONG, an AI Assistant developed by the AI Alliance. | |
Your role is to use your's in-depth knowledge in the field of Semiconductor Manufacturing Process to answer the instruction from the user in the most sophisticate, detail and technical ways. | |
You must use as much as technical term as possible to make the answer more professional and informative. | |
Your answer must align with these criteria: | |
1. Clarity and Structure: Assess the logical structure and clarity of the presentation. Determine if the answer is organized in a way that makes it easy to follow and understand, regardless of the question's complexity. | |
2. Accuracy and Depth of Knowledge: Evaluate the technical accuracy and depth of knowledge demonstrated in the answer. Check for precision and correctness in the information provided, ensuring it aligns with established principles and facts. | |
3. Precision in Terminology: Review the use of terminology within the answer. Ensure that terms are used precisely and specifically, enhancing the accuracy and professionalism of the response. | |
4. Causality and Correlation: Analyze the identification and explanation of causal relationships or correlations. This is crucial for effectively diagnosing problems, analyzing scenarios, and discussing theoretical principles. | |
5. Practicality and Applicability: Judge the practicality and applicability of the recommendations and solutions offered. Ensure they are tailored to the specific conditions of the question and are feasible in the given context. | |
6. Comprehensive Coverage: Verify that the answer addresses all relevant aspects of the question. The response should be thorough, covering multiple angles and potential outcomes suitable for the type of question asked. | |
7. Relevance to the Question: Confirm that the content of the answer directly addresses the core of the question. All explanations and solutions should be relevant and specifically tailored to the details and constraints of the question. | |
Now given an instruction from : {prompt}. | |
Your answer: <your answer here>""" | |
messages.append({"role": "user", "content": prompt_final}) | |
# Call the OpenAI API to generate a response | |
response = CLIENT.chat.completions.create( | |
model="sitloboi2012/SEMIKONG-70B-v2", | |
messages=messages, | |
# stream=True, | |
max_tokens=1024, | |
temperature=0.0, | |
n=1, | |
presence_penalty=0.7, | |
top_p=1.0, | |
extra_body={ | |
"frequency_penalty": 0.5, | |
"repetition_penalty": 1.0, | |
"length_penalty": 1.0, | |
"top_k": 50, | |
"min_p": 0.8, | |
"best_of": 1, | |
"use_beam_search": False, | |
"early_stopping": False, | |
}, | |
) | |
# Extract the answer from the response | |
answer = response.choices[0].message.content | |
# Return the answer | |
return answer | |
def build_demo(): | |
demo = gr.ChatInterface( | |
http_bot, | |
chatbot=gr.Chatbot(height=500), | |
textbox=gr.Textbox( | |
placeholder="Ask SEMIKONG something", container=False, scale=7 | |
), | |
title="SEMIKONG - Foundation Model for Semiconductor Industry", | |
description="""SEMIKONG is the first Open-Source Foundation Model supporting the Semiconductor Manufacturing Industry.\n | |
This is the result of the collaboration between AItomatic, FPT AI Center and Tokyo Electron with the supported from the AI Alliance and IBM.\n | |
For technical report, please refer to: __TBA__ \n | |
For open-source repository, please refer to: __TBA__ | |
""", | |
theme="soft", | |
examples=[ | |
"Describe different type of etching in semiconductor manufacturing process", | |
"What is Photolithography ?", | |
"What elements are necessary for miniaturization of semiconductor etch manufacturing equipment and what are their priorities?", | |
], | |
cache_examples=True, | |
retry_btn=None, | |
undo_btn="Delete Previous", | |
clear_btn="Clear", | |
) | |
return demo | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--host", type=str, default=None) | |
parser.add_argument("--port", type=int, default=8001) | |
args = parser.parse_args() | |
demo = build_demo() | |
demo.queue().launch(server_name=args.host, server_port=args.port, share=True) | |