Jankidepala commited on
Commit
31e5b90
·
verified ·
1 Parent(s): ab8a90d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -99
app.py CHANGED
@@ -1,111 +1,39 @@
1
- import argparse
2
- import gradio as gr
3
- from openai import OpenAI
4
 
5
- MODEL = "pentagoniac/SEMIKONG-8b-GPTQ"
6
 
7
- def http_bot(prompt, history):
8
 
9
- messages = []
 
 
 
10
 
11
- prompt_final = f"""You are SEMIKONG, an AI Assistant developed by the AI Alliance.
12
- 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.
13
- You must use as much as technical term as possible to make the answer more professional and informative.
14
- Your answer must align with these criteria:
15
- 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.
16
- 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.
17
- 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.
18
- 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.
19
- 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.
20
- 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.
21
- 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.
22
- Now given an instruction from : {prompt}.
23
- Your answer: <your answer here>"""
24
-
25
- messages.append({"role": "user", "content": prompt_final})
26
 
27
- # client = OpenAI(api_key="sk-proj-U4WDruCnBYaUFJHaStvAT3BlbkFJ8buf9OOPTbFmmuGomSqN", base_url="http://semikong.aitomatic.com:8081/v1")
28
- # response = client.chat.completions.create(
29
- # model=MODEL,
30
- # messages=messages,
31
- # # stream=True,
32
- # max_tokens=1024,
33
- # temperature=0.0,
34
- # n=1,
35
- # presence_penalty=0.7,
36
- # top_p=1.0,
37
- # extra_body={
38
- # "frequency_penalty": 0.5,
39
- # "repetition_penalty": 1.0,
40
- # "length_penalty": 1.0,
41
- # "top_k": 50,
42
- # "min_p": 0.8,
43
- # "best_of": 1,
44
- # "use_beam_search": False,
45
- # "early_stopping": False,
46
- # },
47
- # )
48
 
49
- # # Extract the answer from the response
50
- # answer = response.choices[0].message.content
51
 
52
- # # Return the answer
53
- # return answer
 
54
 
55
- # css = """
56
- # <style>
57
- # .centered-content {
58
- # text-align: center;
59
- # margin: auto;
60
- # max-width: 800px;
61
- # }
62
- # .centered-content h2 {
63
- # color: #333;
64
- # margin-bottom: 20px;
65
- # }
66
- # .centered-content p {
67
- # color: #666;
68
- # line-height: 1.6;
69
- # }
70
- # </style>
71
- # """
72
 
 
 
 
 
73
 
74
- # description = (
75
- # css
76
- # + """
77
- # <div class="centered-content">
78
- # <h2>The world's first open-source LLM designed specifically for the semiconductor industry.</h2>
79
- # <p>SemiKong is a collaborative open-source effort with support from Aitomatic, TEL, FPT AI Center, The AI Alliance</p>
80
- # </div>
81
- # """
82
- # )
83
 
84
 
85
-
86
- # def build_demo():
87
- # demo = gr.ChatInterface(
88
- # http_bot,
89
- # chatbot=gr.Chatbot(height=600),
90
- # textbox=gr.Textbox(
91
- # placeholder="Ask SEMIKONG something", container=False, scale=7
92
- # ),
93
- # title="SEMIKONG-8B-GPTQ",
94
- # description=description,
95
- # theme="soft",
96
- # cache_examples=False,
97
- # retry_btn=None,
98
- # undo_btn="Delete Previous",
99
- # clear_btn="Clear",
100
- # )
101
- # return demo
102
-
103
-
104
- # if __name__ == "__main__":
105
- # parser = argparse.ArgumentParser()
106
- # parser.add_argument("--host", type=str, default=None)
107
- # parser.add_argument("--port", type=int, default=8001)
108
- # args = parser.parse_args()
109
-
110
- # demo = build_demo()
111
- # demo.queue().launch()
 
1
+ from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
2
+ from langchain_openai import ChatOpenAI
 
3
 
 
4
 
5
+ model = ChatOpenAI(api_key='sk-proj-U4WDruCnBYaUFJHaStvAT3BlbkFJ8buf9OOPTbFmmuGomSqN')
6
 
7
+ messages = [
8
+ SystemMessage(content="Solve the following math problems"),
9
+ HumanMessage(content="What is 81 divided by 9?"),
10
+ ]
11
 
12
+ # Invoke the model with messages
13
+ result = model.invoke(messages)
14
+ print(f"Answer from AI: {result.content}")
 
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ chat_history = [] # Use a list to store messages
 
18
 
19
+ # Set an initial system message (optional)
20
+ system_message = SystemMessage(content="You are a helpful AI assistant.")
21
+ chat_history.append(system_message) # Add system message to chat history
22
 
23
+ # Chat loop
24
+ while True:
25
+ query = input("You: ")
26
+ if query.lower() == "exit":
27
+ break
28
+ chat_history.append(HumanMessage(content=query)) # Add user message
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ # Get AI response using history
31
+ result = model.invoke(chat_history)
32
+ response = result.content
33
+ chat_history.append(AIMessage(content=response)) # Add AI message
34
 
35
+ print(f"AI: {response}")
 
 
 
 
 
 
 
 
36
 
37
 
38
+ print("---- Message History ----")
39
+ print(chat_history)