-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (38 loc) · 1.41 KB
/
app.py
File metadata and controls
49 lines (38 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask, request, jsonify
import os
import openai
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
client = openai.OpenAI(
api_key=os.environ.get("SAMBANOVA_API_KEY"),
base_url="https://api.sambanova.ai/v1",
)
def combine_and_query_model(text1: str, text2: str) -> str:
formatted_text = (f"Input 1: {text1}\nInput 2: {text2}\n\nPlease combine both of these texts "+
f"while eliminating redundancy and formatting the output, do not repeate the prompt, just have the output .")
response = client.chat.completions.create(
model='Meta-Llama-3.1-8B-Instruct',
messages=[
{"role": "system", "content": "You are a robust code merger."},
{"role": "user", "content": formatted_text}
],
temperature=0.1,
top_p=0.1
)
return response.choices[0].message.content
@app.route('/process', methods=['POST'])
def process_text():
if request.method == 'POST':
data = request.get_json()
text1 = data.get('text1', '')
text2 = data.get('text2', '')
if not text1 or not text2:
return jsonify({'error': 'Please provide both text1 and text2'}), 400
try:
result = combine_and_query_model(text1, text2)
return jsonify({"response":result})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run()