|
@@ -2,6 +2,7 @@ import io
|
|
|
import os
|
|
|
import json
|
|
|
|
|
|
+import requests
|
|
|
from openai import OpenAI
|
|
|
from flask import Flask, request, jsonify, send_from_directory, url_for
|
|
|
|
|
@@ -97,7 +98,7 @@ def vision(message, image_url=None, image_b64=None):
|
|
|
chat_messages.append(json_payload)
|
|
|
print(chat_messages)
|
|
|
json_response = app.openai_client.chat.completions.create(
|
|
|
- model="gpt-4-vision-preview",
|
|
|
+ model="gpt-4o",
|
|
|
messages=chat_messages,
|
|
|
max_tokens=500
|
|
|
)
|
|
@@ -151,7 +152,7 @@ def gpt():
|
|
|
if summarize:
|
|
|
chat_messages = app.summary_messages.copy()
|
|
|
max_char_msg = 2000
|
|
|
- max_resp_token = 4096
|
|
|
+ max_resp_token = 1000
|
|
|
else:
|
|
|
chat_messages = app.chat_messages.copy()
|
|
|
json_payload['payload'][-1]['content'] = f"Please summarize this article:\n" + \
|
|
@@ -174,7 +175,7 @@ def gpt():
|
|
|
islamic_response = app.openai_client.chat.completions.create(model="gpt-3.5-turbo", # GPT-3.5 Turbo engine
|
|
|
messages=islam_messages,
|
|
|
max_tokens=2, temperature=0.5)
|
|
|
- if 'Ya' in islamic_response.choices[0].message['content']:
|
|
|
+ if 'Ya' in islamic_response.choices[0].message.content:
|
|
|
greeting_message = f"Buatkan respons chatbot berupa greeting dari chat perusahaan bernama {company_name} pada jam {timestamp}, tidak perlu mention waktu, dan jawab dengan 'Assalamu'alaikum...' terlebih dahulu"
|
|
|
else:
|
|
|
greeting_message = f"Buatkan respons chatbot berupa greeting dari chat perusahaan bernama {company_name} pada jam {timestamp}, tidak perlu mention waktu"
|
|
@@ -273,7 +274,7 @@ def train():
|
|
|
"n_epochs": 5
|
|
|
}
|
|
|
)
|
|
|
- app.logger.info({"mock": "yes", "status": job.status, "job_id": job.id})
|
|
|
+ app.logger.info({"mock": "no", "status": job.status, "job_id": job.id})
|
|
|
return {"status": job.status, "job_id": job.id}
|
|
|
else:
|
|
|
app.logger.info({"mock": "yes", "status": "ok"})
|
|
@@ -295,6 +296,52 @@ def train_with_id(job_id):
|
|
|
app.logger.error(error_print)
|
|
|
return {"status": "Could not find job from id"}
|
|
|
|
|
|
+@app.route('/llama', methods=['POST'])
|
|
|
+def llama():
|
|
|
+ max_char_msg = 500
|
|
|
+ max_resp_token = 600
|
|
|
+ json_payload = request.get_json()
|
|
|
+ if not json_payload:
|
|
|
+ json_payload = []
|
|
|
+ has_named_params = False
|
|
|
+ if isinstance(json_payload, dict):
|
|
|
+ has_named_params = 'payload' in json_payload
|
|
|
+ if 'payload' in json_payload:
|
|
|
+ json_payload = json_payload['payload']
|
|
|
+ if isinstance(json_payload, dict):
|
|
|
+ json_payload = [json_payload]
|
|
|
+ else:
|
|
|
+ json_payload = [json_payload]
|
|
|
+ message = json_payload[-1]
|
|
|
+ content = message['content']
|
|
|
+ content_arr = content.split(" ")
|
|
|
+ new_content_arr = content[:max_char_msg].split(" ")
|
|
|
+ new_content_len = len(new_content_arr)
|
|
|
+ arr = []
|
|
|
+ for i in range(new_content_len):
|
|
|
+ arr.append(content_arr[i])
|
|
|
+ content = " ".join(arr)
|
|
|
+ content = content + " Jawab dengan Bahasa Indonesia"
|
|
|
+ try:
|
|
|
+ json_request = {
|
|
|
+ "model": "llama3",
|
|
|
+ "prompt": content,
|
|
|
+ "stream": False
|
|
|
+ }
|
|
|
+ r = requests.post("http://localhost:11434/api/generate", json=json_request)
|
|
|
+ if r.status_code == 200:
|
|
|
+ result = {
|
|
|
+ "role": "assistant",
|
|
|
+ "content": r.json()["response"]
|
|
|
+ }
|
|
|
+ else:
|
|
|
+ result = {}, r.status_code
|
|
|
+ except Exception as error_print:
|
|
|
+ app.logger.error(error_print)
|
|
|
+ result = {}, 405
|
|
|
+ return result
|
|
|
+
|
|
|
+
|
|
|
|
|
|
# Press the green button in the gutter to run the script.
|
|
|
if __name__ == '__main__':
|