-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3ac66b
commit 3b00050
Showing
15 changed files
with
176 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: CI | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
paths: | ||
- '**.py' | ||
- '**.yml' | ||
- '**.toml' | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- '**.py' | ||
- '**.yml' | ||
- '**.toml' | ||
|
||
jobs: | ||
pypi-publish: | ||
name: Upload release to PyPI | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: chartboost/ruff-action@v1 | ||
with: | ||
args: 'format --check' | ||
- uses: chartboost/ruff-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import json, csv | ||
import json | ||
import csv | ||
import subprocess | ||
|
||
# https://github.com/f/awesome-chatgpt-prompts/ | ||
url = 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv' | ||
url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv" | ||
|
||
|
||
def main(): | ||
out = subprocess.getoutput(f'curl -s {url}') | ||
rdr = csv.reader(out.split('\n')) | ||
out = subprocess.getoutput(f"curl -s {url}") | ||
rdr = csv.reader(out.split("\n")) | ||
roles = {} | ||
for row in rdr: | ||
name = row[0].replace(' ', '-').replace('`', '').replace('/', '-').lower() | ||
if name == 'act': | ||
name = row[0].replace(" ", "-").replace("`", "").replace("/", "-").lower() | ||
if name == "act": | ||
# skip first row | ||
continue | ||
|
||
content = row[1] | ||
roles[name] = content | ||
|
||
with open('roles.json', 'w') as f: | ||
with open("roles.json", "w") as f: | ||
f.write(json.dumps(roles, indent=4)) | ||
|
||
if __name__ == '__main__': | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from .app import main | ||
|
||
__all__ = ["main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from .app import main | ||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
import json, os | ||
import json | ||
import os | ||
from ..utils.http import TimeoutSession | ||
from ..utils.common import * | ||
from ..utils.conf import * | ||
from .history import DummyHistory, FileHistory | ||
|
||
HIST_SEP = '==========' | ||
HIST_SEP = "==========" | ||
|
||
|
||
# https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-completion | ||
class Ollama(object): | ||
def __init__(self, base_url, model, role, timeout): | ||
self.base_url = base_url | ||
self.http_session = TimeoutSession(timeout=timeout) | ||
if ENABLE_HISTORY: | ||
self.history_file = FileHistory(os.path.join(CONF_PATH, 'history')) | ||
self.history_file = FileHistory(os.path.join(CONF_PATH, "history")) | ||
else: | ||
self.history_file = DummyHistory() | ||
self.model = model | ||
self.role = role | ||
|
||
def generate(self, prompt, stream=True): | ||
url = self.base_url + '/api/chat' | ||
debug_print(f"generate: {prompt} to {url} with model {self.model} role {self.role} and stream {stream}") | ||
url = self.base_url + "/api/chat" | ||
debug_print( | ||
f"generate: {prompt} to {url} with model {self.model} role {self.role} and stream {stream}" | ||
) | ||
system_content = ROLE_CONTENT.get(self.role, self.role) | ||
payload = { | ||
'messages': [ | ||
{'role': 'system', 'content': system_content, 'name': 'ShellGPT'}, | ||
{'role': 'user', 'content': prompt, 'name': 'user'}, | ||
"messages": [ | ||
{"role": "system", "content": system_content, "name": "ShellGPT"}, | ||
{"role": "user", "content": prompt, "name": "user"}, | ||
], | ||
'model': self.model, | ||
'stream': stream | ||
"model": self.model, | ||
"stream": stream, | ||
} | ||
debug_print(f'Infer message: {payload}') | ||
debug_print(f"Infer message: {payload}") | ||
r = self.http_session.post(url, json=payload, stream=stream) | ||
if r.status_code != 200: | ||
raise Exception("Error: " + r.text) | ||
|
||
answer = '' | ||
answer = "" | ||
for item in r.iter_content(chunk_size=None): | ||
resp = json.loads(item) | ||
if resp['done'] is False: | ||
content = resp['message']['content'] | ||
if resp["done"] is False: | ||
content = resp["message"]["content"] | ||
answer += content | ||
yield content | ||
else: | ||
self.history_file.write(fr'''{now_ms()},{resp['eval_duration']},{resp['eval_count']} | ||
self.history_file.write(rf"""{now_ms()},{resp['eval_duration']},{resp['eval_count']} | ||
{prompt} | ||
{HIST_SEP} | ||
{answer} | ||
{HIST_SEP} | ||
''') | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.