mangoman7002
commited on
Commit
·
4e510e1
1
Parent(s):
9dfac8f
Model added
Browse files
api.py
DELETED
@@ -1,39 +0,0 @@
|
|
1 |
-
import mdtex2html
|
2 |
-
from flask import Flask, request, jsonify
|
3 |
-
from chat import converse
|
4 |
-
import json
|
5 |
-
|
6 |
-
app = Flask(__name__)
|
7 |
-
|
8 |
-
@app.route("/", methods=['GET', 'POST'])
|
9 |
-
def home():
|
10 |
-
try:
|
11 |
-
par = request.get_json()
|
12 |
-
if not par:
|
13 |
-
return jsonify({"error": "Invalid JSON input"}), 400
|
14 |
-
|
15 |
-
conversation = par.get('conversation')
|
16 |
-
provider = par.get('provider')
|
17 |
-
model = par.get('model')
|
18 |
-
api = par.get('api')
|
19 |
-
|
20 |
-
if not all([conversation, provider, model, api]):
|
21 |
-
return jsonify({"error": "Missing required parameters"}), 400
|
22 |
-
|
23 |
-
load = json.loads(converse(conversation, provider, model, api))
|
24 |
-
load['DirectResult'] = load['content']
|
25 |
-
|
26 |
-
try:
|
27 |
-
load['content'] = mdtex2html.convert(load['content'])
|
28 |
-
except Exception as e:
|
29 |
-
return jsonify({"error": f"Error converting content: {str(e)}"}), 500
|
30 |
-
|
31 |
-
toreturn = json.dumps(load, indent=4)
|
32 |
-
# print(toreturn)
|
33 |
-
return toreturn, 200
|
34 |
-
|
35 |
-
except Exception as e:
|
36 |
-
return jsonify({"error": str(e)}), 500
|
37 |
-
|
38 |
-
if __name__ == "__main__":
|
39 |
-
app.run(host='0.0.0.0', debug=True, port=1777)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -29,7 +29,7 @@ def home():
|
|
29 |
return jsonify({"error": f"Error converting content: {str(e)}"}), 500
|
30 |
|
31 |
toreturn = json.dumps(load, indent=4)
|
32 |
-
print(toreturn)
|
33 |
return toreturn, 200
|
34 |
|
35 |
except Exception as e:
|
|
|
29 |
return jsonify({"error": f"Error converting content: {str(e)}"}), 500
|
30 |
|
31 |
toreturn = json.dumps(load, indent=4)
|
32 |
+
# print(toreturn)
|
33 |
return toreturn, 200
|
34 |
|
35 |
except Exception as e:
|
chat.py
CHANGED
@@ -1,9 +1,11 @@
|
|
|
|
1 |
import json
|
2 |
from langchain_core.prompts import ChatPromptTemplate
|
3 |
from langchain_groq import ChatGroq
|
4 |
from langchain.chains import ConversationChain
|
5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
6 |
from langchain_core.output_parsers import JsonOutputParser
|
|
|
7 |
from langchain_cohere import ChatCohere
|
8 |
def langchainConversation(conversation):
|
9 |
prompts = []
|
@@ -18,6 +20,10 @@ def converse(conversation,provider,model,key,other:dict={}):
|
|
18 |
chat = ChatGoogleGenerativeAI(model=model,google_api_key=key)
|
19 |
elif(provider=='cohere'):
|
20 |
chat = ChatCohere(model=model,cohere_api_key=key)
|
|
|
|
|
|
|
|
|
21 |
else:
|
22 |
return json.dumos({'content':'unspported Provider'})
|
23 |
return json.dumps(json.loads(chat.invoke(langchainConversation(conversation)).json()),indent=4)
|
|
|
1 |
+
from langchain_openai import ChatOpenAI
|
2 |
import json
|
3 |
from langchain_core.prompts import ChatPromptTemplate
|
4 |
from langchain_groq import ChatGroq
|
5 |
from langchain.chains import ConversationChain
|
6 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
7 |
from langchain_core.output_parsers import JsonOutputParser
|
8 |
+
|
9 |
from langchain_cohere import ChatCohere
|
10 |
def langchainConversation(conversation):
|
11 |
prompts = []
|
|
|
20 |
chat = ChatGoogleGenerativeAI(model=model,google_api_key=key)
|
21 |
elif(provider=='cohere'):
|
22 |
chat = ChatCohere(model=model,cohere_api_key=key)
|
23 |
+
elif(provider=='lepton'):
|
24 |
+
url = f'https://{model}.lepton.run/api/v1/'
|
25 |
+
print(url)
|
26 |
+
chat = ChatOpenAI(openai_api_base = url,openai_api_key=key)
|
27 |
else:
|
28 |
return json.dumos({'content':'unspported Provider'})
|
29 |
return json.dumps(json.loads(chat.invoke(langchainConversation(conversation)).json()),indent=4)
|
requirements.txt
CHANGED
@@ -6,4 +6,5 @@ langchain-community
|
|
6 |
jq
|
7 |
flask
|
8 |
mdtex2html
|
9 |
-
langchain_cohere
|
|
|
|
6 |
jq
|
7 |
flask
|
8 |
mdtex2html
|
9 |
+
langchain_cohere
|
10 |
+
langchain_openai
|