Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for local LLM models via Ollama #30

Open
wants to merge 267 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
267 commits
Select commit Hold shift + click to select a range
1dc233b
Upgrading version before publish
kedarchandrayan Apr 2, 2024
bf3e50e
Upgrading messages version
kedarchandrayan Apr 2, 2024
20095f0
Refactored extension code
Apr 2, 2024
453e0de
config store management used and made the terminal singelton
dakshbhardwaj Apr 2, 2024
f773e8a
Merge pull request #24 from sirji-ai/pypi-packages
kedarchandrayan Apr 3, 2024
3af565b
conflict resolved.
kedarchandrayan Apr 3, 2024
bffb71f
Merge pull request #25 from sirji-ai/ui
kedarchandrayan Apr 3, 2024
eef1a65
Renamed the pycode to py_scripts
V-R-Dighe Apr 3, 2024
185d9b9
Setup virtual env for Python
kedarchandrayan Apr 3, 2024
d0e47f7
Invoke agent with venv python
kedarchandrayan Apr 3, 2024
f5e911e
bug fix
kedarchandrayan Apr 3, 2024
b1d4120
bug fix
kedarchandrayan Apr 3, 2024
5cd92df
added environment config flow
dakshbhardwaj Apr 3, 2024
7a99fe7
Updated the conversation history with new parsed_content key in agent…
V-R-Dighe Apr 3, 2024
dff7adc
Agent runner scripts
kedarchandrayan Apr 3, 2024
33c662b
Updating the versions for publish
kedarchandrayan Apr 3, 2024
9506a6e
Updating the dependency versions for vs code extension
kedarchandrayan Apr 3, 2024
9b3fdbb
making the agent runner files self sufficient.
kedarchandrayan Apr 3, 2024
ef1d803
Read workspace folder path from environment variable
kedarchandrayan Apr 4, 2024
70e13ae
Raise ValueError if workspace environment variable not found.
kedarchandrayan Apr 4, 2024
cbc8b1b
Dependency versions increased.
kedarchandrayan Apr 4, 2024
1af58a2
refactored code for workspace path and integerated coder.py
dakshbhardwaj Apr 4, 2024
4e4d9b6
commited .prietterc file
dakshbhardwaj Apr 4, 2024
a4b108c
Python middleware script for Research Agent
kedarchandrayan Apr 4, 2024
68832e4
Added support for inform, question, solution complete action in coder…
V-R-Dighe Apr 4, 2024
c472f6d
Added support for step started and step completed action in coder age…
V-R-Dighe Apr 4, 2024
38a83b8
Updated the planner system prompt for steps list
V-R-Dighe Apr 4, 2024
4dc46c1
Updated the parse steps method to handle the non Step prefix steps
V-R-Dighe Apr 4, 2024
7994dac
Updated the planner system prompt for steps list
V-R-Dighe Apr 4, 2024
3221c01
Removed the creation only in current directory instruction from syste…
V-R-Dighe Apr 4, 2024
4603b39
Updated the planner system prompt for steps list
V-R-Dighe Apr 4, 2024
d115df9
Readded the creation only in current directory instruction from syste…
V-R-Dighe Apr 4, 2024
3edf4b7
README changes and LICENSE inclusion in packages.
kedarchandrayan Apr 4, 2024
573a834
Updated the package versions
V-R-Dighe Apr 4, 2024
7936646
Install playwright in virtual env
V-R-Dighe Apr 4, 2024
c59b1b8
planner UI
dakshbhardwaj Apr 4, 2024
dc1065d
planner UI
dakshbhardwaj Apr 4, 2024
7d166c1
Fixed icon placement
Apr 4, 2024
9d14540
Fixed the icons on top-right corner
Apr 4, 2024
393ddaf
added the logic for displaying progress bar once we receive steps
dakshbhardwaj Apr 4, 2024
9288a36
Update README.md
kedarchandrayan Apr 4, 2024
e832197
added the functionality to disable and enable the send button
dakshbhardwaj Apr 4, 2024
e9fb1d5
added return from createFile
dakshbhardwaj Apr 5, 2024
d14e848
Integrated sirji run id environment variable
V-R-Dighe Apr 5, 2024
8fa5176
added handling for executor
dakshbhardwaj Apr 5, 2024
deb14de
Added support for executor message construction in coding agent adapter
V-R-Dighe Apr 5, 2024
e39f48f
Version update
kedarchandrayan Apr 5, 2024
47055c0
Version update
kedarchandrayan Apr 5, 2024
237c370
Update README.md
kedarchandrayan Apr 5, 2024
7682da2
Added capability for read file and read directory
kedarchandrayan Apr 5, 2024
77a98a3
Updated the parser
V-R-Dighe Apr 5, 2024
4eade0c
Version update for publish
kedarchandrayan Apr 5, 2024
817f079
Updated the versions of packages
V-R-Dighe Apr 5, 2024
200d330
Bug fix - missing break in case.
kedarchandrayan Apr 5, 2024
9b91e26
added sirJiRunId to env vars
dakshbhardwaj Apr 5, 2024
c29dd01
added a placeholder message when send button is disabled
dakshbhardwaj Apr 5, 2024
63f374f
Adding the FILE READ and DIR READ capability
kedarchandrayan Apr 5, 2024
1a9e133
Updated svg icons
GadhariSachin Apr 5, 2024
b92a44f
Added header background color
GadhariSachin Apr 5, 2024
7d211b1
Adjust textarea height on changing placeholder text
GadhariSachin Apr 5, 2024
ec998de
added log line
kedarchandrayan Apr 5, 2024
14836a5
Fixed checkboxes UI in planner modal
GadhariSachin Apr 5, 2024
3300a72
handled solution completed step seperately
dakshbhardwaj Apr 5, 2024
541dd52
Search without Google API
kedarchandrayan Apr 5, 2024
38d6c4a
Version update
kedarchandrayan Apr 5, 2024
62b7ab3
Removed the usage of google search api key
V-R-Dighe Apr 5, 2024
4245810
Update README.md
kedarchandrayan Apr 5, 2024
5e1da32
Fixing README heart on PyPI
kedarchandrayan Apr 5, 2024
d57a743
README changes for sirji-messagesw and sirji-tools
kedarchandrayan Apr 5, 2024
2b2a149
README changes to sirji-agents
kedarchandrayan Apr 5, 2024
6b6b706
Added retry on invalid message recieved
kedarchandrayan Apr 5, 2024
751a310
Handling MessageValidationError too
kedarchandrayan Apr 6, 2024
d2cfe12
Version bump
kedarchandrayan Apr 6, 2024
46f1454
Update README.md
kedarchandrayan Apr 6, 2024
5ecb81e
Update README.md
kedarchandrayan Apr 6, 2024
6d87953
Update README.md
kedarchandrayan Apr 6, 2024
365adc7
Update README.md
kedarchandrayan Apr 6, 2024
0c8a54f
fix for progress bar not updating
dakshbhardwaj Apr 7, 2024
f6ddf2c
Steps for collaborators added in the readme.
kedarchandrayan Apr 7, 2024
7b6f301
A TODO added in README.
kedarchandrayan Apr 7, 2024
03210e7
Steps for collaborators added in the readme.
kedarchandrayan Apr 7, 2024
c6f79df
Minor changes to readme
kedarchandrayan Apr 7, 2024
0eeb9de
Added support for local models via Ollama
devparanjay Apr 8, 2024
9624e8d
Added SIRJI_OLLAMA_MODEL env variable to ModelClient
devparanjay Apr 8, 2024
0018e26
Set model values as model from ModelClient
devparanjay Apr 8, 2024
cec6ca3
Updated README slightly for Ollama support
devparanjay Apr 8, 2024
5bd56b9
Added python-dotenv to requirements.txt
devparanjay Apr 8, 2024
1513581
Update README.md
kedarchandrayan Apr 8, 2024
a1a7772
Update README.md
kedarchandrayan Apr 8, 2024
1ccf430
Moving files from Dogfood inside sirji/desktop folder
kedarchandrayan Apr 8, 2024
ffb1cd1
Removing the unused script.
kedarchandrayan Apr 8, 2024
60c1464
Updated .gitignore
kedarchandrayan Apr 8, 2024
81a6b7a
handled error when directory already exists
dakshbhardwaj Apr 8, 2024
e23b56e
disabled input box while workspace is getting readu
dakshbhardwaj Apr 8, 2024
822770b
Update README.md
kedarchandrayan Apr 8, 2024
6c3d931
move the setUpHistory manger from init to when user provides the pro…
dakshbhardwaj Apr 8, 2024
05843e0
Verbose bot messages.
kedarchandrayan Apr 8, 2024
2bd11c0
added commands for package and publishing
dakshbhardwaj Apr 8, 2024
3d26555
Fixed the typo
V-R-Dighe Apr 8, 2024
7e9abd0
Changed the minimum version requirement for VS Code.
kedarchandrayan Apr 8, 2024
017991c
fix undefined error in updateStepStatus function
dakshbhardwaj Apr 8, 2024
1b67241
updated types vscode version
dakshbhardwaj Apr 8, 2024
3fc5452
Updated chat terminal UI
GadhariSachin Apr 8, 2024
0a527fb
Total tokens added for Research Agent
kedarchandrayan Apr 8, 2024
255303c
Merge branch 'vs-code-extension' into sachin/chat-terminal-ui
GadhariSachin Apr 8, 2024
0ea8370
removed icon class
GadhariSachin Apr 8, 2024
64ee9f8
Updated the sirji agents package to return the tokens consumed
V-R-Dighe Apr 8, 2024
5acbeaa
Version update
kedarchandrayan Apr 8, 2024
c7937ae
Updated the agents package with handling for methods with 0 tokens ut…
V-R-Dighe Apr 8, 2024
f7d8451
Updated the sirji agents pacakge with tokens usage changes
V-R-Dighe Apr 8, 2024
b6b7c4a
Get total tokens and tokens usage in dollar implementation
V-R-Dighe Apr 8, 2024
a082850
COMTRIBUTING.md
kedarchandrayan Apr 8, 2024
dcc02dc
ISSUES.md
kedarchandrayan Apr 8, 2024
912e8d1
PyPI packages
kedarchandrayan Apr 8, 2024
997864f
CONTRIBUTING.md
kedarchandrayan Apr 8, 2024
d80302d
Check prerequisites script
kedarchandrayan Apr 8, 2024
523f2bf
Linked the check prerequisites script from README
kedarchandrayan Apr 8, 2024
bc3808b
Removed the workspace
kedarchandrayan Apr 8, 2024
a882f4a
change execute command from terminal to vscode.task
dakshbhardwaj Apr 8, 2024
9e0b652
VS Code version support
Apr 9, 2024
a8e1cc1
added a case for handling tokens
dakshbhardwaj Apr 9, 2024
951e98c
Merge branch 'vs-code-extension' into sachin/chat-terminal-ui
GadhariSachin Apr 9, 2024
9c38f99
WIP - display tokens
GadhariSachin Apr 9, 2024
6c6b49b
Update README.md
kedarchandrayan Apr 9, 2024
928d5db
Update CONTRIBUTING.md
kedarchandrayan Apr 9, 2024
b6d91b9
Update the tokens used in UI
GadhariSachin Apr 9, 2024
cfe875c
Merge branch 'vs-code-extension' of https://github.com/sirji-ai/sirji…
GadhariSachin Apr 9, 2024
5a57af7
updated checks in execute task
dakshbhardwaj Apr 9, 2024
fa3a77d
Updated settings modal UI
GadhariSachin Apr 9, 2024
301bdd6
Printing the python script execution error on chat terminal and allow…
V-R-Dighe Apr 9, 2024
d4ab042
added events for coder, executor and researcher
dakshbhardwaj Apr 9, 2024
ffbf8f5
System prompt changes for CODER and PLANNER
kedarchandrayan Apr 9, 2024
3446102
Tooltip UI feedbacks
GadhariSachin Apr 9, 2024
be2fcb2
Merge branch 'vs-code-extension' of https://github.com/sirji-ai/sirji…
GadhariSachin Apr 9, 2024
f062547
Added run server action
kedarchandrayan Apr 9, 2024
fae7b89
changed execute command execution logic
dakshbhardwaj Apr 9, 2024
a91477e
Run server support in vs code extension
kedarchandrayan Apr 9, 2024
9a00d18
Special handling of source command
kedarchandrayan Apr 9, 2024
8058e31
Added planner, coder and researcher tabs
GadhariSachin Apr 9, 2024
a552b43
Merge branch 'vs-code-extension' of https://github.com/sirji-ai/sirji…
GadhariSachin Apr 9, 2024
6eb8668
updated vscode extension version
dakshbhardwaj Apr 9, 2024
b188152
UI fixes
GadhariSachin Apr 9, 2024
8c6c530
reduced the timeout
Apr 9, 2024
5a2f94e
added logo, keywords and discussion url in package.json
dakshbhardwaj Apr 9, 2024
f9c1b7b
changed image logo path
dakshbhardwaj Apr 9, 2024
2a004a7
Removing the parathesis
kedarchandrayan Apr 10, 2024
e8785db
Updated the toolbard UI
GadhariSachin Apr 10, 2024
986ff18
Added hover effect on toolbar icons
GadhariSachin Apr 10, 2024
d59dcb1
Product Manager and Architect Agents Added.
kedarchandrayan Apr 10, 2024
894c9a0
added handling for sperating execute command and server
dakshbhardwaj Apr 10, 2024
490c071
Updating the version
kedarchandrayan Apr 10, 2024
063ec23
Added loading indicator at bot side
GadhariSachin Apr 10, 2024
95a5b73
Changes for avoiding chained commands and not to give up
kedarchandrayan Apr 10, 2024
d2df254
updated version
dakshbhardwaj Apr 10, 2024
b759fb9
Update README.md
nishithz Apr 10, 2024
7068ec8
Update README.md
nishithz Apr 10, 2024
3620680
Added loading indicator at bot side
GadhariSachin Apr 10, 2024
69a8697
Update README.md
nishithz Apr 10, 2024
5f842bf
updated copy
GadhariSachin Apr 10, 2024
2ebd354
Merge branch 'vs-code-extension' of https://github.com/sirji-ai/sirji…
GadhariSachin Apr 10, 2024
05fd516
Create README.md
kedarchandrayan Apr 10, 2024
c6e5589
Update README.md
kedarchandrayan Apr 10, 2024
3928826
Update README.md
kedarchandrayan Apr 10, 2024
9bb69c5
Update README.md
kedarchandrayan Apr 10, 2024
0caf810
Update README.md
kedarchandrayan Apr 10, 2024
ec69a74
Merge pull request #43 from sirji-ai/vs-code-extension
nishithz Apr 10, 2024
82eaa2f
changed the model to gpt-4-turbo from gpt-4-turbo-preview
kedarchandrayan Apr 12, 2024
817131f
changed command execution from terminal to spawn
dakshbhardwaj Apr 12, 2024
d864c2a
Prompt changes to increase reliability.
kedarchandrayan Apr 12, 2024
256ee79
Version updates
kedarchandrayan Apr 12, 2024
ec692e4
updated vs code extension version and removed output file from execut…
dakshbhardwaj Apr 12, 2024
fcb91ba
Output format for run server logs passed to the llm
kedarchandrayan Apr 12, 2024
9abfbb4
README changes
kedarchandrayan Apr 12, 2024
a84fcb7
Merge pull request #46 from sirji-ai/reliability
V-R-Dighe Apr 12, 2024
7bd4708
Scroll to bottom on switching tabs
GadhariSachin Apr 15, 2024
d52eacf
Create pytest_on_pr.yml
kedarchandrayan Apr 15, 2024
133e472
For testing the test case run.
kedarchandrayan Apr 15, 2024
e71ae6d
Update pytest_on_pr.yml
kedarchandrayan Apr 15, 2024
ce5f271
setting env vars.
kedarchandrayan Apr 15, 2024
33fcc89
Adding env var and some cleanup
kedarchandrayan Apr 15, 2024
41b1915
Update pytest_on_pr.yml
kedarchandrayan Apr 15, 2024
71da2c8
Python version change for test case run
kedarchandrayan Apr 15, 2024
e765f6d
Py version change for running test cases
kedarchandrayan Apr 15, 2024
c8a23ec
Update pytest_on_pr.yml
kedarchandrayan Apr 15, 2024
96d1df6
Merge pull request #68 from sirji-ai/pytest-on-pr
sunilkhedar Apr 15, 2024
138836f
Publish workflow
kedarchandrayan Apr 15, 2024
2f13009
Merge pull request #75 from sirji-ai/pypi-publish-workflow
sunilkhedar Apr 16, 2024
00ffcdc
Updated toolbar and send button colors
GadhariSachin Apr 16, 2024
84a789f
added model-provider
Apr 16, 2024
1a2ec5d
removed param
Apr 16, 2024
658da42
readme.md exports
Apr 16, 2024
a9cbf0c
edited readme
Apr 16, 2024
ed480b3
Minor changes and version bump
kedarchandrayan Apr 16, 2024
94411fa
Merge pull request #76 from atharva101/model_provider
kedarchandrayan Apr 16, 2024
1ea5c7a
Moved chat UI terminal in seperate window
GadhariSachin Apr 17, 2024
398955f
Capitlaize the tab buttons text
GadhariSachin Apr 17, 2024
6ffff5d
Added steps and logs panel
GadhariSachin Apr 17, 2024
711b6e2
UI Review fixes
GadhariSachin Apr 17, 2024
39c51a1
Create __init__.py
kedarchandrayan Apr 17, 2024
4ed9109
Update setup.py
kedarchandrayan Apr 17, 2024
6af76e3
Update requirements.txt
kedarchandrayan Apr 17, 2024
dc185fb
Merge pull request #77 from sirji-ai/bug-fix
sunilkhedar Apr 17, 2024
eb85fa6
clean up
GadhariSachin Apr 18, 2024
393c832
Added trsnsition effect while resizing and fixed drag issue.
GadhariSachin Apr 18, 2024
7100189
Added vscode extension changelog
kreloaded Apr 18, 2024
606fc55
Added horizontal scroll to logs tab buttons and toggle arrow
GadhariSachin Apr 18, 2024
6dd4579
debounce the resizing events
GadhariSachin Apr 18, 2024
8d5cc29
Added github action ro publish to vscode marketplace
kreloaded Apr 18, 2024
0c81789
Merge pull request #78 from sirji-ai/github-workflow
V-R-Dighe Apr 18, 2024
085886c
Added pwd command in github action
kreloaded Apr 18, 2024
3dfd29e
Merge pull request #79 from sirji-ai/github-workflow
V-R-Dighe Apr 18, 2024
eeb096d
Added pwd for debugging
kreloaded Apr 18, 2024
da55957
Added steps in single run command
kreloaded Apr 18, 2024
6b3b492
Fixed resizer smoothing issue
GadhariSachin Apr 18, 2024
4c64d30
Fixed input box height issue
GadhariSachin Apr 18, 2024
13cadd6
Minor fix
GadhariSachin Apr 18, 2024
839697a
Merge branch 'main' into sachin/split-screen-ui
GadhariSachin Apr 18, 2024
1433634
Updated the changelog file
V-R-Dighe Apr 18, 2024
268fb26
Updated the changelog with issue links and new versions change log
V-R-Dighe Apr 18, 2024
a225ab5
Updated the github workflow with the vsix file upload to s3 changes
V-R-Dighe Apr 18, 2024
c259269
Updated the github workflow with the vsix file upload to s3 changes
V-R-Dighe Apr 18, 2024
ab80669
Updated the github workflow with the vsix file upload to s3 changes
V-R-Dighe Apr 18, 2024
30ac324
Updated the github workflow with the vsix file upload to s3 changes
V-R-Dighe Apr 18, 2024
d0b281e
Updated the github workflow with the vsix file upload to s3 changes
V-R-Dighe Apr 18, 2024
b493460
Uncommented the publish command from workflow
V-R-Dighe Apr 18, 2024
641bc5c
Merge pull request #81 from sirji-ai/changelog
sunilkhedar Apr 18, 2024
12a64f8
Merge pull request #82 from sirji-ai/github-workflow
sunilkhedar Apr 18, 2024
8ce70fb
Merge pull request #83 from sirji-ai/sachin/split-screen-ui
sunilkhedar Apr 18, 2024
ee42208
Added publish to open vsx support in github workflow
V-R-Dighe Apr 18, 2024
3c06428
Added publish to open vsx support in github workflow
V-R-Dighe Apr 18, 2024
360b52a
Merge pull request #84 from sirji-ai/open-vsx-publish
sunilkhedar Apr 18, 2024
9efb138
changes for making sirji compatibility to windows
dakshbhardwaj Apr 19, 2024
df7c8cf
removed os hardcoding
dakshbhardwaj Apr 19, 2024
87e3f7f
Update README.md
kedarchandrayan Apr 21, 2024
31cd225
Update README.md
kedarchandrayan Apr 21, 2024
0ee7f18
Update README.md
kedarchandrayan Apr 21, 2024
4b340bf
Update README.md
kedarchandrayan Apr 21, 2024
8b250a1
Update README.md
kedarchandrayan Apr 21, 2024
785b206
Update README.md
kedarchandrayan Apr 21, 2024
92b4418
Update README.md
kedarchandrayan Apr 21, 2024
bf3b66a
Update README.md
kedarchandrayan Apr 22, 2024
bdafdde
Update README.md
kedarchandrayan Apr 22, 2024
be46a5e
Update README.md
kedarchandrayan Apr 22, 2024
279f268
Merge pull request #107 from sirji-ai/roadmap
sunilkhedar Apr 22, 2024
27d2510
Merge pull request #86 from sirji-ai/windows-compatibility
kedarchandrayan Apr 23, 2024
98fe853
Added Ollama as a model provider and upodated README with relevant in…
devparanjay Apr 24, 2024
34ffb5c
Updated README
devparanjay Apr 24, 2024
1e52383
Merge branch 'main' into upstream
devparanjay Apr 24, 2024
5508f1c
Fixed JS syntax
devparanjay Apr 24, 2024
54bd021
Fixed README.md
devparanjay Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SIRJI_OPENAI_API_KEY=sk-none
SIRJI_USE_OLLAMA=true
SIRJI_OLLAMA_MODEL=gemma:2b
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ __pycache__/

# Virtual environment
venv
.venv

.DS_Store
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Follow these [setup steps](./docs/setup-steps.md) to start Sirji.

## Capabilities<a name="capabilities"></a>

Sirji is being built using Python. It currently uses OpenAI chat completions API and OpenAI assistants API.
Sirji is being built using Python. It currently uses OpenAI chat completions API and OpenAI assistants API. Sirji works with either an OpenAI API key to use GPT 4, or a local model via Ollama.

To begin with, it will be equipped with:

Expand Down Expand Up @@ -46,7 +46,7 @@ The sequence diagram below shows how the user initiates Sirji by giving a proble

## Supported AI Models<a name="supported-ai-models"></a>

We are planning to use the `gpt-4-turbo-preview` model for the dogfood release. But the package will be designed to be composable for supporting other AI models too.
We are planning to use the `gpt-4-turbo-preview` model for the dogfood release. ~~But the package will be designed to be composable for supporting other AI models too.~~ It should now work with local models via Ollama.

## Contribution

Expand Down
109 changes: 61 additions & 48 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import sys
import uuid
import os
import queue
import shutil
import textwrap
import re
import threading
import queue
import time

from sirji.view.terminal import open_terminal_and_run_command
from sirji.view.screen import get_screen_resolution
from sirji.view.chat import send_external_system_message, run_chat_app, disable_chat_send_button, enable_chat_send_button

from sirji.tools.logger import coder as cLogger
from sirji.tools.logger import researcher as rLogger
from sirji.tools.logger import planner as pLogger
from sirji.tools.logger import executor as eLogger
from sirji.tools.logger import sirji as sLogger
from sirji.tools.logger import user as uLogger
from dotenv import load_dotenv

from sirji.agents.coder import Coder
from sirji.agents.executor import Executor
from sirji.agents.planner import Planner
from sirji.agents.researcher import Researcher
from sirji.agents.executor import Executor
from sirji.agents.user import User

from sirji.messages.parser import MessageParser
from sirji.tools.logger import coder as cLogger
from sirji.tools.logger import executor as eLogger
from sirji.tools.logger import planner as pLogger
from sirji.tools.logger import researcher as rLogger
from sirji.tools.logger import sirji as sLogger
from sirji.tools.logger import user as uLogger
from sirji.view.chat import (
disable_chat_send_button,
enable_chat_send_button,
run_chat_app,
send_external_system_message,
)
from sirji.view.screen import get_screen_resolution
from sirji.view.terminal import open_terminal_and_run_command


from sirji.messages.problem_statement import ProblemStatementMessage
last_recipient = ''
last_recipient = ""

# Global queue to safely exchange messages between threads
messages_queue = queue.Queue()
Expand All @@ -40,7 +39,7 @@ def empty_workspace():

# List all files and directories in the workspace directory
for item in os.listdir(workspace_dir):
if (item == "logs"):
if item == "logs":
continue # Skip the code directory

item_path = os.path.join(workspace_dir, item)
Expand All @@ -56,14 +55,14 @@ def empty_workspace():
print(f"Error removing {item_path}: {e}")


class Main():
class Main:
def __init__(self):
self.problem_statement = None # Placeholder
self.initialize_logs()

self.coder = Coder()
self.planner = Planner()
self.researcher = Researcher('openai_assistant', 'openai_assistant')
self.researcher = Researcher("openai_assistant", "openai_assistant")
self.executor = Executor()
self.user = User()

Expand All @@ -78,40 +77,49 @@ def truncate_logs(self):
# Check if the file exists at the given location
if os.path.exists(logger.filepath):
# File exists, so open it in 'w' mode to clear or create it, then immediately close it
open(logger.filepath, 'w').close()
open(logger.filepath, "w").close()
else:
# If the file does not exist, handle accordingly (e.g., log this situation or take other actions)
print(f"File does not exist at {logger.filepath}.")

except AttributeError:
# Handle the case where the logger doesn't have a 'filepath' attribute
print(
f"Logger {logger} does not have a 'filepath' attribute.")
print(f"Logger {logger} does not have a 'filepath' attribute.")

except IOError as e:
# Handle other I/O errors, such as permission errors
print(
f"Failed to open file for logger {logger} at {logger.filepath}: {e}")
f"Failed to open file for logger {logger} at {logger.filepath}: {e}"
)

def initialize_logs(self):
# Truncate the logs
self.truncate_logs()

# Initialize the logs
cLogger.initialize_logs(
"Coder: Specializing in generating and modifying code, this agent is skilled in various programming languages and is equipped to handle tasks ranging from quick fixes to developing complex algorithms.\n\n\n")
"Coder: Specializing in generating and modifying code, this agent is skilled in various programming languages and is equipped to handle tasks ranging from quick fixes to developing complex algorithms.\n\n\n"
)

rLogger.initialize_logs("Researcher: dives into vast pools of information to find answers, evidence, or data that support the task at hand. Whether it's through browsing the web, accessing databases, or consulting academic journals, this agent is adept at gathering and synthesizing relevant information to aid in problem-solving.\n\n\n")
rLogger.initialize_logs(
"Researcher: dives into vast pools of information to find answers, evidence, or data that support the task at hand. Whether it's through browsing the web, accessing databases, or consulting academic journals, this agent is adept at gathering and synthesizing relevant information to aid in problem-solving.\n\n\n"
)

pLogger.initialize_logs("Planner: planner is tasked with orchestrating the overall strategy for solving user queries. Assesses the problem statement and determines the most effective sequence of actions, delegating tasks to other agents and tools as necessary. This agent ensures that Sirji's workflow is efficient and goal-oriented.\n\n\n")
pLogger.initialize_logs(
"Planner: planner is tasked with orchestrating the overall strategy for solving user queries. Assesses the problem statement and determines the most effective sequence of actions, delegating tasks to other agents and tools as necessary. This agent ensures that Sirji's workflow is efficient and goal-oriented.\n\n\n"
)

eLogger.initialize_logs("Executor: responsible for running code or scripts in a controlled environment, allowing for executing and testing activities. Executor verifies the correctness and efficacy of solutions before they are finalized and implements automated tasks as defined by the Planner.\n\n\n")
eLogger.initialize_logs(
"Executor: responsible for running code or scripts in a controlled environment, allowing for executing and testing activities. Executor verifies the correctness and efficacy of solutions before they are finalized and implements automated tasks as defined by the Planner.\n\n\n"
)

sLogger.initialize_logs(
"Sirji: Sirji will automatically create a plan to solve the problem statement, prioritize it, organize research, write code, execute it, and fix issues.\n\n\n")
"Sirji: Sirji will automatically create a plan to solve the problem statement, prioritize it, organize research, write code, execute it, and fix issues.\n\n\n"
)

uLogger.initialize_logs(
"User: The user is the person who interacts with Sirji. The user can ask questions, provide problem statements, and receive solutions from Sirji.\n\n\n")
"User: The user is the person who interacts with Sirji. The user can ask questions, provide problem statements, and receive solutions from Sirji.\n\n\n"
)

def open_views(self):
screen_width, screen_height = get_screen_resolution()
Expand All @@ -123,18 +131,21 @@ def open_views(self):
(f"watch -n 1 'cat {pLogger.filepath}'", "Plan Progress"),
(f"tail -f {rLogger.filepath}", "Research Agent"),
(f"tail -f {cLogger.filepath}", "Coding Agent"),
(f"tail -f {eLogger.filepath}", "Execution Agent")
(f"tail -f {eLogger.filepath}", "Execution Agent"),
]

current_directory = os.getcwd()

# Prepend `cd {current_directory} &&` to each command to ensure it runs in the desired directory
command_title_pairs = [(f"cd {current_directory} && {command}", title)
for command, title in command_title_pairs]
command_title_pairs = [
(f"cd {current_directory} && {command}", title)
for command, title in command_title_pairs
]

for i, (command, title) in enumerate(command_title_pairs):
open_terminal_and_run_command(
command, title, i, window_width, window_height)
command, title, i, window_width, window_height
)

def _parse_response(self, response_str):
"""
Expand All @@ -156,7 +167,7 @@ def handle_response(self, message):
recipient = response.get("TO").strip()
sender = response.get("FROM").strip()
action = response.get("ACTION").strip()
except Exception as e:
except Exception:
recipient = last_recipient
message = textwrap.dedent(f"""
```
Expand All @@ -172,31 +183,30 @@ def handle_response(self, message):
action = response.get("ACTION").strip()

send_external_system_message(
f"Forwarding message from {sender} to {recipient} for action: {action}")

response_message = ''
f"Forwarding message from {sender} to {recipient} for action: {action}"
)

response_message = ""

if (action == "question" or action == "inform"):
if action == "question" or action == "inform":
details = response.get("DETAILS")
send_external_system_message(f"Question: {details}")
enable_chat_send_button()

user_input = self.wait_for_user_input()

ans_message = self.user.generate_answer_message(
user_input, 'Coder')
ans_message = self.user.generate_answer_message(user_input, "Coder")

disable_chat_send_button()
self.handle_response(ans_message)
elif (action == 'solution-complete'):
elif action == "solution-complete":
details = response.get("DETAILS")
send_external_system_message(f" Solution complete: {details}")
enable_chat_send_button()

user_input = self.wait_for_user_input()

ans_message = self.user.generate_feedback_message(
user_input, 'Coder')
ans_message = self.user.generate_feedback_message(user_input, "Coder")
disable_chat_send_button()
self.handle_response(ans_message)

Expand All @@ -223,7 +233,8 @@ def start(self):
self.open_views()

send_external_system_message(
"Hello! Please provide the problem you need me to solve.")
"Hello! Please provide the problem you need me to solve."
)

while True:
# Wait for a new message to become available
Expand All @@ -234,7 +245,8 @@ def start(self):
disable_chat_send_button()

ps_message = self.user.generate_problem_statement_message(
self.problem_statement, 'Coder')
self.problem_statement, "Coder"
)

response_message = self.coder.message(ps_message)

Expand All @@ -258,6 +270,7 @@ def perform_non_gui_tasks():

if __name__ == "__main__":
empty_workspace()
load_dotenv()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loaded dotenv


background_thread = threading.Thread(target=perform_non_gui_tasks)
background_thread.start()
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added python-dotenv

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ beautifulsoup4==4.12.3
pypdf2==3.0.1
markdownify==0.11.6
pyobjc==10.2
playwright==1.42.0
playwright==1.42.0
python-dotenv==1.0.1
31 changes: 13 additions & 18 deletions sirji/agents/coder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from openai import OpenAI
import os

from sirji.config.model import ModelClient
from sirji.prompts.coder import CoderPrompt

from sirji.tools.logger import coder as cLogger


Expand All @@ -11,6 +8,7 @@ class SingletonMeta(type):
This is a metaclass that will be used to create a Singleton class.
It ensures that only one instance of the Singleton class exists.
"""

_instances = {}

def __call__(cls, *args, **kwargs):
Expand All @@ -24,37 +22,34 @@ class Coder(metaclass=SingletonMeta):
def __init__(self):
# Initialize conversation
self.conversation = [
{'role': 'system', 'content': CoderPrompt().system_prompt()}]
{"role": "system", "content": CoderPrompt().system_prompt()}
]

# Fetch OpenAI API key from environment variable
api_key = os.environ.get("SIRJI_OPENAI_API_KEY")
# Initialize ModelClient
model_client = ModelClient()

if api_key is None:
raise ValueError(
"OpenAI API key is not set as an environment variable")

# Initialize OpenAI client
self.client = OpenAI(api_key=api_key)
# Set self.client as the value of self.client set in ModelClient class
self.client = model_client.client
self.model = model_client.model

def message(self, input_message):
# Append user's input message to the conversation
self.conversation.append({'role': 'user', 'content': input_message})
self.conversation.append({"role": "user", "content": input_message})

cLogger.info(f"Incoming: \n{input_message}")

cLogger.info("Calling OpenAI Chat Completions API")

chat_completion = self.client.chat.completions.create(
messages=self.conversation,
model="gpt-4-turbo-preview",
model=self.model,
temperature=0,
max_tokens=4095,
)

response_message = chat_completion.choices[0].message.content

self.conversation.append(
{'role': 'assistant', 'content': response_message})

self.conversation.append({"role": "assistant", "content": response_message})

cLogger.info(f"Outgoing: \n{response_message}")
return response_message
Loading