Skip to content

Commit

Permalink
update: change to python code
Browse files Browse the repository at this point in the history
  • Loading branch information
namtranase committed Mar 10, 2024
1 parent 379948f commit a1b84f1
Show file tree
Hide file tree
Showing 29 changed files with 191 additions and 337 deletions.
4 changes: 0 additions & 4 deletions config/temi_config.json

This file was deleted.

3 changes: 3 additions & 0 deletions configs/sevrer_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"url": "http://127.0.0.1:8080"
}
5 changes: 5 additions & 0 deletions playground/sever_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"server_executable": "llama.cpp/build/bin/server",
"model_path": "/home/namtd/workspace/personal/kicopilot/playground/models/model.gguf",
"c": 2048
}
9 changes: 0 additions & 9 deletions scripts/build_llamacpp.sh

This file was deleted.

2 changes: 0 additions & 2 deletions scripts/install_temi.sh

This file was deleted.

File renamed without changes.
13 changes: 13 additions & 0 deletions scripts/llamacpp_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if [! -d llama.cpp/build ]; then
echo "Building the llamacpp ..."
cd llama.cpp
mkdir -p build
rm -rf build/*
cd build
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS
cmake --build . --config Release -- -j$(nproc)
cd ../..
fi

echo "Starting the llamcpp server ..."
./llama.cpp/build/bin/server -m /home/namtd/workspace/personal/kicopilot/playground/models/model.gguf -c 128 --host 0.0.0.0 --port 8080
File renamed without changes.
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from setuptools import setup, find_packages

setup(
name='temi',
version='2.0.0',
packages=find_packages(),
entry_points={
'console_scripts': [
'temi = src.temi_interface:main',
],
},
# Add all necessary package requirements here
install_requires=[
'requests',
# Add other dependencies needed for your package
],
# Metadata
author='Nam Tran',
author_email='[email protected]',
description='An assistant in your terminal powered by llama.cpp',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/namtranase/terminalmind', # Use the URL to the github repo.
project_urls={
'Source': 'https://github.com/namtranase/terminalmind',
# Add any other relevant links here
},
)
Empty file added src/__init__.py
Empty file.
Empty file added src/modules/__init__.py
Empty file.
Empty file.
30 changes: 30 additions & 0 deletions src/modules/assistant/assistant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class AssistantGit:
def __init__(self) -> None:
pass

def get_response(self, api_func, user_input):
completion_options = {
"temperature": 0.7,
"top_k": 50,
# ... include other options as needed ...
}
prompt = f"### Human: {user_input}\n### Assistant: "
response = api_func(prompt, **completion_options)

return response


class AssistantTerminal:
def __init__(self) -> None:
pass

def get_response(self, api_func, user_input):
completion_options = {
"temperature": 0.7,
"top_k": 50,
# ... include other options as needed ...
}
prompt = f"### Human: {user_input}\n### Assistant: "
response = api_func(prompt, **completion_options)

return response
17 changes: 17 additions & 0 deletions src/modules/chat/chat_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ChatModel:
def __init__(self, instruction):
self.instruction = instruction
self.chat_history = []

def format_chat_prompt(self, user_input):
formatted_chat = f"{self.instruction}\n"
for i, message in enumerate(self.chat_history):
speaker = "Human" if i % 2 == 0 else "Assistant"
formatted_chat += f"### {speaker}: {message}\n"
formatted_chat += f"### Human: {user_input}\n### Assistant: "
return formatted_chat

def format_prompt(self, user_input):
formatted_chat = f"{self.instruction}\n"
formatted_chat += f"### Human: {user_input}\n### Assistant: "
return formatted_chat
Empty file.
21 changes: 21 additions & 0 deletions src/modules/function_calling/function_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class ChatModel:
def __init__(self, instruction):
self.instruction = instruction
self.chat_history = []

def format_chat_prompt(self, user_input):
formatted_chat = f"{self.instruction}\n"
for i, message in enumerate(self.chat_history):
speaker = "Human" if i % 2 == 0 else "Assistant"
formatted_chat += f"### {speaker}: {message}\n"
formatted_chat += f"### Human: {user_input}\n### Assistant: "
return formatted_chat

def format_prompt(self, user_input):
formatted_chat = f"{self.instruction}\n"
formatted_chat += f"### Human: {user_input}\n### Assistant: "
return formatted_chat

class TermFuncCall:
def __init__(self) -> None:
pass
9 changes: 9 additions & 0 deletions src/prompt_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class PromptWrapper:
def __init__(self) -> None:
pass

def get_assistant_prompt(self):
return None

def get_function_call_prompt(self):
return None
File renamed without changes.
62 changes: 62 additions & 0 deletions src/temi_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import json

from server_wrapper import ServerWrapper
from prompt_wrapper import PromptWrapper
from .modules.assistant.assistant import AssistantTerminal, AssistantGit
from .modules.function_calling.function_model import TermFuncCall

import argparse

class TemiInterface:
def __init__(self, config_path="configs/server_config"):
config = None
with open(config_path, "r", encoding="utf-8") as config_file:
config = json.load(config_file)

self.config = config
self.server_wrapper = ServerWrapper(config=config)
self.prompt_wrapper = PromptWrapper()
self.ast_terminal = AssistantTerminal()
self.ast_git = AssistantGit()
self.term_func = TermFuncCall()

def check_server_status(self):
status = self.server_wrapper.check_server()
return status

def handle_assitant(self, user_input):
print(user_input)
if "git" in user_input:
return self.ast_git.get_response(self.server_wrapper.generate_completion, user_input)
else:
return self.ast_terminal.get_response(self.server_wrapper.generate_completion, user_input)


def main():
parser = argparse.ArgumentParser(description='temi - Your Terminal Assistant')
subparsers = parser.add_subparsers(dest='command')

# Parser for "check server" command
server_parser = subparsers.add_parser('check', help='Check the temi server status')
server_parser.add_argument('status', nargs='?', help='The "status" argument to check the server')

# Parser for "assistant" command
query_parser = subparsers.add_parser('assistant', help='Assistant mode')
query_parser.add_argument('user_input', nargs='+', help='The question or command for temi to process')

args = parser.parse_args()
temi_interface = TemiInterface("/home/namtd/workspace/personal/terminalmind/configs/sevrer_config.json")

if args.command == 'check':
status = temi_interface.check_server_status()
print(status)
elif args.command == 'assistant':
# Join the list of user_input into a single string
user_input = ' '.join(args.user_input)
answer = temi_interface.handle_assitant(user_input)
print(answer)
else:
parser.print_help()

if __name__ == "__main__":
main()
Empty file added src/utils/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions src/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def trim(s):
return s.strip()
8 changes: 0 additions & 8 deletions temi-packaging/DEBIAN/control

This file was deleted.

14 changes: 0 additions & 14 deletions temi-packaging/DEBIAN/postinst

This file was deleted.

61 changes: 0 additions & 61 deletions temi-packaging/usr/local/bin/config_setup.sh

This file was deleted.

29 changes: 0 additions & 29 deletions temi-packaging/usr/local/bin/extract_pdf_content.py

This file was deleted.

34 changes: 0 additions & 34 deletions temi-packaging/usr/local/bin/fetch_article_content.py

This file was deleted.

Loading

0 comments on commit a1b84f1

Please sign in to comment.