Skip to content

Commit

Permalink
clipboard feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfer0x80 committed May 26, 2024
1 parent 50c55b4 commit 56f4293
Show file tree
Hide file tree
Showing 27 changed files with 816 additions and 642 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ https://github.com/ollama/ollama/blob/main/docs/import.md#manually-converting--q


````
docker
https://www.youtube.com/watch?v=m0fc6ZPb6NU
https://www.geoffreylitt.com/2023/03/25/llm-end-user-programming.html
https://ollama.com/blog/ollama-is-now-available-as-an-official-docker-image
https://hub.docker.com/r/ollama/ollama
https://collabnix.com/getting-started-with-ollama-and-docker/
https://docs.coqui.ai/en/latest/inference.html
https://github.com/valiantlynx/ollama-docker
improve
https://www.geoffreylitt.com/2023/03/25/llm-end-user-programming
https://blog.waleson.com/2024/05/the-long-long-tail-of-ai-applications.html
https://www.strangeloopcanon.com/p/what-can-llms-never-do
https://jxnl.co/writing/2024/05/22/systematically-improving-your-rag/#cluster-and-model-topics
````

````
Expand Down
41 changes: 41 additions & 0 deletions bin/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from dataclasses import dataclass

from jsonargparse import CLI

from llmpeg.agent import Agent


@dataclass()
class Main:
rational_model: str
trigger_model: str
speech_model_size: str
hear_model_size: str

def __post_init__(self):
self.agent = Agent(
self.rational_model, self.trigger_model, self.speech_model_size, self.hear_model_size
)

def run(self):
# NOTE: [EDITABLE]

self.agent.chat()
# self.agent.summarize_search('https://news.mit.edu/2020/brain-reading-computer-code-1215')
# self.agent.explain_search('https://news.mit.edu/2020/brain-reading-computer-code-1215')

# ----------------


def main():
try:
CLI(Main)
return 0
except KeyboardInterrupt:
return 0
except ValueError:
return 0


if __name__ == '__main__':
exit(main())
37 changes: 0 additions & 37 deletions llmpeg/__main__.py

This file was deleted.

22 changes: 11 additions & 11 deletions llmpeg/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

@dataclass
class Actions:
cache_dir: Path
rational_model: str # ollama/llama3
trigger_model: str # ollama/gemma:2b
speech_model_size: str # tts_models/en/jenny/jenny
hear_model_size: str # openai-whisper/base
cache_dir: Path
rational_model: str # ollama/llama3
trigger_model: str # ollama/gemma:2b
speech_model_size: str # tts_models/en/jenny/jenny
hear_model_size: str # openai-whisper/base

def __post_init__(self) -> None:
self.rational = BrainRational(self.rational_model)
self.trigger = BrainTrigger(self.trigger_model, self.cache_dir)
self.hear = Hear(self.speech_model_size, self.cache_dir)
self.speech = Speech(self.hear_model_size, self.cache_dir)
self.vision = Vision()
def __post_init__(self) -> None:
self.rational = BrainRational(self.rational_model)
self.trigger = BrainTrigger(self.trigger_model, self.cache_dir)
self.hear = Hear(self.speech_model_size, self.cache_dir)
self.speech = Speech(self.hear_model_size, self.cache_dir)
self.vision = Vision()
43 changes: 22 additions & 21 deletions llmpeg/actions/brain/rational.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,34 @@


# TODO: have a conversation with preprompted character roleplay and play songs on request
# TODO: this should be a in front of browser and call it todo stuff instead of bypassing this and using capabilities directly
# TODO: this should be a in front of browser and call it todo stuff
# TODO: instead of bypassing this and using capabilities directly
@dataclass
class BrainRational:
model: str # NOTE: e.g. "gemma:2b"
explain_prompt: str = 'Explain the following data which was extracted from a webpage in your own words'
summarize_prompt: str = 'Summarize the following data which was extracted from a webpage'
model: str # NOTE: e.g. "gemma:2b"
explain_prompt: str = 'Explain the following data which was extracted from a webpage in your own words'
summarize_prompt: str = 'Summarize the following data which was extracted from a webpage'

# TODO: sqlite3 for storing chat history
def __post_init__(self) -> None:
self.chat_messages = []
self.llm = LLM(self.model)
# TODO: sqlite3 for storing chat history
def __post_init__(self) -> None:
self.chat_messages = []
self.llm = LLM(self.model)

def summarize(self, prompt: str) -> str:
return self.llm.generate(f'{self.summarize_prompt}\n{prompt}')
def summarize(self, prompt: str) -> str:
return self.llm.generate(f'{self.summarize_prompt}\n{prompt}')

def explain(self, prompt: str) -> str:
return self.llm.generate(f'{self.explain_prompt}\n{prompt}')
def explain(self, prompt: str) -> str:
return self.llm.generate(f'{self.explain_prompt}\n{prompt}')

def respond(self, prompt: str) -> str:
return self.llm.generate(prompt)
def respond(self, prompt: str) -> str:
return self.llm.generate(prompt)

def clear_chat(self) -> None:
self.chat_messages = []
def clear_chat(self) -> None:
self.chat_messages = []

def _add_message(self, prompt) -> None:
return self.chat_messages.append({'role': 'user', 'content': prompt})
def _add_message(self, prompt) -> None:
return self.chat_messages.append({'role': 'user', 'content': prompt})

def chat(self, prompt: str) -> Union[str, list[str]]:
self._add_message(prompt)
return self.llm.recall_generate(self.chat_messages[-1]['content'], self.chat_messages)
def chat(self, prompt: str) -> Union[str, list[str]]:
self._add_message(prompt)
return self.llm.recall_generate(self.chat_messages[-1]['content'], self.chat_messages)
128 changes: 82 additions & 46 deletions llmpeg/actions/brain/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,85 @@

@dataclass
class BrainTrigger:
model_name: str
cache_dir: Path

# TODO: LLM for NLP
def __post_init__(self):
self.cache_dir = self.cache_dir / 'triggers'
Path.mkdir(self.cache_dir, exist_ok=True)
self.llm = LLM(self.model_name)
os.environ['NLTK_DATA'] = str(self.cache_dir / 'nltk_data')
nltk.download(self.model_name) # NOTE: e.g. "punkt"

def _find_intent(self, instruction: str) -> str:
return (
f'Complete the following text: Given the instruction "{instruction}". '
+ 'Categorize it as "play music", "research web". "chat with me". The answer is '
)

def find_intent(self, prompt: str) -> str:
response = self.llm.generate(self._find_intent(prompt))
if self.check_audio_request(response):
return 'play'
elif self.check_browse_request(response):
return 'browse'
elif self.check_explain_request(response):
return 'chat'

def check_greeting(self, prompt: str) -> bool:
return any(keyword in nltk.tokenize.word_tokenize(prompt.lower()) for keyword in TriggerList.greeting)

def check_goodbye(self, text: str) -> bool:
return any(keyword in nltk.tokenize.word_tokenize(text.lower()) for keyword in TriggerList.goodbye) or all(
keyword in nltk.tokenize.word_tokenize(text.lower()) for keyword in TriggerList.goodbye_default_phrase
)

def check_browse_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return True if TriggerList.browse_start in tokens and any(keyword in tokens for keyword in TriggerList.browse_check) else False

def check_explain_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return True if TriggerList.explain_start in tokens and any(keyword in tokens for keyword in TriggerList.explain_check) else False

# TODO: find sentiment to play song or not
def check_audio_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return True if TriggerList.audio_start in tokens and any(keyword in tokens for keyword in TriggerList.audio_check) else False
model_name: str
cache_dir: Path

# TODO: LLM for NLP
def __post_init__(self):
self.cache_dir = self.cache_dir / 'triggers'
Path.mkdir(self.cache_dir, exist_ok=True)
self.llm = LLM(self.model_name)
os.environ['NLTK_DATA'] = str(self.cache_dir / 'nltk_data')
nltk.download(self.model_name) # NOTE: e.g. "punkt"

def _find_intent(self, instruction: str) -> str:
return (
f'Complete the following text: Given the instruction "{instruction}". '
+ 'Categorize it as "play music", "research web". "chat with me". The answer is '
)

def find_intent(self, prompt: str) -> str:
response = self.llm.generate(self._find_intent(prompt))
if self.check_audio_request(response):
return 'play'
elif self.check_browse_request(response):
return 'browse'
elif self.check_explain_request(response):
return 'chat'

def check_greeting(self, prompt: str) -> bool:
return any(keyword in nltk.tokenize.word_tokenize(prompt.lower()) for keyword in TriggerList.greeting)

def check_goodbye(self, text: str) -> bool:
return any(
keyword in nltk.tokenize.word_tokenize(text.lower()) for keyword in TriggerList.goodbye
) or all(
keyword in nltk.tokenize.word_tokenize(text.lower())
for keyword in TriggerList.goodbye_default_phrase
)

def check_chat_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return (
True
if TriggerList.chat_start in tokens
and any(keyword in tokens for keyword in TriggerList.chat_check)
else False
)

def check_browse_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return (
True
if TriggerList.browse_start in tokens
and any(keyword in tokens for keyword in TriggerList.browse_check)
else False
)

def check_summarize_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return (
True
if TriggerList.summarize_start in tokens
and any(keyword in tokens for keyword in TriggerList.summarize_check)
else False
)

def check_explain_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return (
True
if TriggerList.explain_start in tokens
and any(keyword in tokens for keyword in TriggerList.explain_check)
else False
)

# TODO: find sentiment to play song or not
def check_audio_request(self, text: str) -> bool:
tokens = nltk.tokenize.word_tokenize(text.lower())
return (
True
if TriggerList.audio_start in tokens
and any(keyword in tokens for keyword in TriggerList.audio_check)
else False
)
Loading

0 comments on commit 56f4293

Please sign in to comment.