Compare commits
No commits in common. "89cc832a6b47ebdf7813ca2436248c90c52c6bb2" and "2327fc343a67a6dba5898c6368f491403eee9c90" have entirely different histories.
89cc832a6b
...
2327fc343a
10 changed files with 1 additions and 106 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -35,6 +35,4 @@ yarn-error.log*
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
|
||||||
|
api_key.txt
|
||||||
.idea/
|
|
||||||
venv/
|
|
3
py/.idea/.gitignore
vendored
3
py/.idea/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
|
@ -1,6 +0,0 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<settings>
|
|
||||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
|
||||||
<version value="1.0" />
|
|
||||||
</settings>
|
|
||||||
</component>
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Black">
|
|
||||||
<option name="sdkName" value="Python 3.12" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
|
||||||
<component name="PyCharmProfessionalAdvertiser">
|
|
||||||
<option name="shown" value="true" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,8 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/py.iml" filepath="$PROJECT_DIR$/.idea/py.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,13 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="PYTHON_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager">
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
<component name="PackageRequirementsSettings">
|
|
||||||
<option name="versionSpecifier" value="Greater or equal (>=x.y.z)" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
51
py/api.py
51
py/api.py
|
@ -1,51 +0,0 @@
|
||||||
from flask import Flask, request, jsonify
|
|
||||||
import ollama
|
|
||||||
|
|
||||||
|
|
||||||
class AI:
|
|
||||||
@staticmethod
|
|
||||||
def process_local(model, message, system, return_class, access_token):
|
|
||||||
stream = ollama.chat(
|
|
||||||
model=model,
|
|
||||||
messages=[{'role': 'user', 'content': message}, {'role': 'system', 'content': system}],
|
|
||||||
stream=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
for chunk in stream:
|
|
||||||
print(chunk['message']['content'])
|
|
||||||
return_class.ai_response[access_token] += chunk['message']['content']
|
|
||||||
|
|
||||||
|
|
||||||
class API:
|
|
||||||
def __init__(self):
|
|
||||||
self.app = Flask(__name__)
|
|
||||||
self.ai_response = []
|
|
||||||
self.ai = AI()
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
@self.app.route('/interstellar/api/ai_create', methods=['POST'])
|
|
||||||
def create_ai():
|
|
||||||
self.ai_response.append("")
|
|
||||||
return jsonify({'status': 200, 'access_token': len(self.ai_response) - 1})
|
|
||||||
|
|
||||||
@self.app.route('/interstellar/api/ai_send', methods=['POST'])
|
|
||||||
def send_ai():
|
|
||||||
data = request.get_json()
|
|
||||||
message = data.get('message')
|
|
||||||
ai_model = data.get('ai_model')
|
|
||||||
system_prompt = data.get('system_prompt')
|
|
||||||
access_token = data.get('access_token')
|
|
||||||
self.ai.process_local(ai_model, message, system_prompt, self, access_token)
|
|
||||||
return jsonify({'status': 200})
|
|
||||||
|
|
||||||
@self.app.route('/interstellar/api/ai_get', methods=['GET'])
|
|
||||||
def get_ai():
|
|
||||||
data = request.args.get('access_token')
|
|
||||||
return jsonify({'status': 200, 'response': self.ai_response[int(data)]})
|
|
||||||
|
|
||||||
self.app.run(debug=True)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
api = API()
|
|
||||||
api.run()
|
|
|
@ -1,4 +0,0 @@
|
||||||
python -m venv venv
|
|
||||||
source venv/bin/activate
|
|
||||||
pip install -r requirements.txt
|
|
||||||
deactivate
|
|
|
@ -1,2 +0,0 @@
|
||||||
flask
|
|
||||||
ollama
|
|
Loading…
Reference in a new issue