devika icon indicating copy to clipboard operation
devika copied to clipboard

Major improvements - add: gemini, mistral - fix:ollama, long polling -Improve:UI, backend

Open ARajgor opened this issue 1 year ago β€’ 24 comments

This PR resolves these issues: https://github.com/stitionai/devika/issues/2 https://github.com/stitionai/devika/issues/3 https://github.com/stitionai/devika/issues/4 https://github.com/stitionai/devika/issues/6 https://github.com/stitionai/devika/issues/16 https://github.com/stitionai/devika/issues/19 https://github.com/stitionai/devika/issues/27 https://github.com/stitionai/devika/issues/29 https://github.com/stitionai/devika/issues/37 https://github.com/stitionai/devika/issues/43 https://github.com/stitionai/devika/issues/46 https://github.com/stitionai/devika/issues/57 https://github.com/stitionai/devika/issues/102 https://github.com/stitionai/devika/issues/119

Note

if this PR is in the draft, it may still have some unstable code. You can You can try at your own risk. currently working on improving backend results.

What's updated

Backend

  • [x] Add Gemini and Mistral models
  • [x] Handle Ollama error in a better way
  • [x] Removing long polling. replace with a socket with threading support
  • [x] add google search
  • [x] update the backend code for optimization
    • [x] reformat the imports so everything is running smoothing in threads
    • [x] Improve the class object initialization method for better management
    • [x] update the parameter and return type of classes and methods
    • [x] reformat the code for better visibility
  • [x] dividing many APIs into flask blueprints
  • [x] make total token workable with socket so real-time
  • [x] combine models, projects, and search engine list APIs
  • [x] prompt and logic improvement

Frontend

  • [x] update the UI to enhance user experience
  • [x] remove long polling. replace with socket
  • [x] Add both settings and logs routes
  • [x] Update the tailwind class and make it responsive
  • [x] Try to minimize the API calls
  • [x] Handle local storage in a better way
  • [x] Add functionality to delete project
  • [x] List the model by companies
  • [x] have the option to select the search engine

overall

  • [x] add sample.config.toml
  • [ ] update README.MD
  • [ ] Improve installation and usage guide

New UI

Screenshot 2024-03-24 192344 image

Setting page: image

Log page: image

Squash and Merge

Maintainers: If you decide to merge this, please remember to Squash and Merge into a single commit, so the helper script and temporary files created by it will not become part of the record. (Apologies if I'm stating the obvious.)

ARajgor avatar Mar 21 '24 21:03 ARajgor

please commit the changed files to main repo

Revanthraja avatar Mar 24 '24 04:03 Revanthraja

please commit the changed files to main repo

Still lot to update. I'll give update in the discord.

ARajgor avatar Mar 24 '24 04:03 ARajgor

Hey @Israel-Laguan thanks for your UI review but wait some time. it's old files and didn't align with the current branch. that's why it is still in draft. I push the latest changes soon.

ARajgor avatar Mar 24 '24 14:03 ARajgor

Hey @ARajgor, I see that this PR packs a lot of changes. Isn’t it time to break down newer additions to smaller ones?

franklinselva avatar Mar 25 '24 23:03 franklinselva

I agree, better to make smaller PRs

Israel-Laguan avatar Mar 25 '24 23:03 Israel-Laguan

Agree and would add, that it would be good to used TAGS and a proper iterative release methodology to help users track major updates.

JoNilsson avatar Mar 25 '24 23:03 JoNilsson

indeed major improvements! about splitting to smaller PRs, one suggestion would be like:

  • apis and UI (lots of great improvements)
  • ollama and agent.py related
  • google search
  • gemini, mistral

lenjoy avatar Mar 26 '24 17:03 lenjoy

There's something blocking, once the agent is busy the server is unresponsive.

Ideally we'd use async in such situations. This happens when the agent is browsing websites via Google.

I might take a look tomorrow, thanks for the great work!

TheOnlyWayUp avatar Mar 26 '24 20:03 TheOnlyWayUp

@ARajgor This is awesome! Thank you for the PR, I will be reviewing the changes soon and see about merging them. This currently has a lot of merge conflicts to be resolved, will look into it! ❀️ πŸ™Œ

mufeedvh avatar Mar 26 '24 21:03 mufeedvh

I would suggest to add the OPENAI_API_BASE parameter to the settings panel so that it can use any compatible OpenAI endpoints, like LMStudio, OLLAMA (this time in a generic way), OpenRouter, DeepSeekCoder, Together.ai and so on.

I would also suggest to add a custom model name (for openAI models) in the models dropdown list. Using an add custom model name edit field and an add button. And then in the dropdown appear under "Custom Models:" line.

Mayorc1978 avatar Mar 26 '24 22:03 Mayorc1978

11 12

File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\sync_api\_context_manager.py", line 48, in __enter__
    raise Error(
playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.
Link ::  https://elogic.co/blog/how-to-write-an-ecommerce-website-requirements-specification-document-tips-tricks-and-best-practices/
Exception in thread Thread-26:
Traceback (most recent call last):
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\pc\Desktop\devika\devika.py", line 97, in <lambda>
    thread = Thread(target=lambda: agent.execute(message, project_name))
  File "C:\Users\pc\Desktop\devika\src\agents\agent.py", line 341, in execute
    search_results = self.search_queries(queries, project_name)
  File "C:\Users\pc\Desktop\devika\src\agents\agent.py", line 91, in search_queries
    browser.go_to(link)
  File "C:\Users\pc\Desktop\devika\src\browser\browser.py", line 22, in go_to
    self.page.goto(url)
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\sync_api\_generated.py", line 8641, in goto
    self._sync(
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_sync_base.py", line 113, in _sync
    return task.result()
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_page.py", line 500, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_frame.py", line 145, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_connection.py", line 59, in send
    return await self._connection.wrap_api_call(
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_connection.py", line 509, in wrap_api_call
    return await cb()
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_connection.py", line 97, in inner_send
    result = next(iter(done)).result()
playwright._impl._errors.TimeoutError: Timeout 30000ms exceeded.


darrassi1 avatar Mar 27 '24 01:03 darrassi1

The "Save" button in the settings menu isn't working properly. It doesn't transmit any data to the back-end, so I had to manually add the API key to the sample.config.toml file to get Gemini functioning.

darrassi1 avatar Mar 27 '24 01:03 darrassi1

I'm going to fix the sync blocking issue and some merge conflicts today.

TheOnlyWayUp avatar Mar 27 '24 02:03 TheOnlyWayUp

Have we considered using langchain anywhere? Langchain aggregates a ton of APIs, it would be cool to let the user choose what LM Service they want to use without us writing API Wrappers for each

TheOnlyWayUp avatar Mar 27 '24 02:03 TheOnlyWayUp

I would suggest to add the OPENAI_API_BASE parameter to the settings panel so that it can use any compatible OpenAI endpoints, like LMStudio, OLLAMA (this time in a generic way), OpenRouter, DeepSeekCoder, Together.ai and so on.

I would also suggest to add a custom model name (for openAI models) in the models dropdown list. Using an add custom model name edit field and an add button. And then in the dropdown appear under "Custom Models:" line.

Good idea! If this feature req is open when I write my code, I'll throw it in with the config updates

Last I checked the UI doesn't stream responses, I did see some socket code though. What's that used for @ARajgor?

TheOnlyWayUp avatar Mar 27 '24 02:03 TheOnlyWayUp

The "Save" button in the settings menu isn't working properly. It doesn't transmit any data to the back-end, so I had to manually add the API key to the sample.config.toml file to get Gemini functioning.

you have to create config.toml file. sample.config.toml is for reference. check the readme.md file in my pr.

ARajgor avatar Mar 27 '24 05:03 ARajgor

11 12

File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\sync_api\_context_manager.py", line 48, in __enter__
    raise Error(
playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.
Please use the Async API instead.
Link ::  https://elogic.co/blog/how-to-write-an-ecommerce-website-requirements-specification-document-tips-tricks-and-best-practices/
Exception in thread Thread-26:
Traceback (most recent call last):
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Users\pc\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\pc\Desktop\devika\devika.py", line 97, in <lambda>
    thread = Thread(target=lambda: agent.execute(message, project_name))
  File "C:\Users\pc\Desktop\devika\src\agents\agent.py", line 341, in execute
    search_results = self.search_queries(queries, project_name)
  File "C:\Users\pc\Desktop\devika\src\agents\agent.py", line 91, in search_queries
    browser.go_to(link)
  File "C:\Users\pc\Desktop\devika\src\browser\browser.py", line 22, in go_to
    self.page.goto(url)
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\sync_api\_generated.py", line 8641, in goto
    self._sync(
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_sync_base.py", line 113, in _sync
    return task.result()
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_page.py", line 500, in goto
    return await self._main_frame.goto(**locals_to_params(locals()))
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_frame.py", line 145, in goto
    await self._channel.send("goto", locals_to_params(locals()))
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_connection.py", line 59, in send
    return await self._connection.wrap_api_call(
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_connection.py", line 509, in wrap_api_call
    return await cb()
  File "C:\Users\pc\Desktop\devika\.venv\lib\site-packages\playwright\_impl\_connection.py", line 97, in inner_send
    result = next(iter(done)).result()
playwright._impl._errors.TimeoutError: Timeout 30000ms exceeded.

I'd fix that issue with running everything in thread but let me check.

ARajgor avatar Mar 27 '24 05:03 ARajgor

@ARajgor This is awesome! Thank you for the PR, I will be reviewing the changes soon and see about merging them. This currently has a lot of merge conflicts to be resolved, will look into it! ❀️ πŸ™Œ

sorry for very big and long PR but I keep facing new problems and want add more functionalities and features so I keep added. Next time I'll make sure to push only one module.

ARajgor avatar Mar 27 '24 05:03 ARajgor

Beautiful changes, I hope to use them as soon as possible

rr13k avatar Mar 27 '24 08:03 rr13k

    `def search_queries(self, queries: list, project_name: str) -> dict:
    results = {}

    def run_search():
        nonlocal results
        knowledge_base = KnowledgeBase()
        if self.engine == "Google":
            engine = GoogleSearch()
        else:
            engine = DuckDuckGoSearch()
        browser = Browser()

        for query in queries:
            query = query.strip().lower()

            """ Check if the knowledge base already has the query learned """
            # knowledge = knowledge_base.get_knowledge(tag=query)
            # if knowledge:
            #     results[query] = knowledge
            #     continue

            """ Search for the query and get the first link """
            engine.search(query)
            link = engine.get_first_link()
            print("Link :: ", link)
            """ Browse to the link and take a screenshot, then extract the text """
            browser.go_to(link)
            browser.screenshot(project_name)

            """ Formatter Agent is invoked to format and learn from the contents """
            results[query] = self.formatter.execute(
                browser.extract_text(),
                project_name
            )

            """ Add the newly acquired data to the knowledge base """
            # knowledge_base.add_knowledge(tag=query, contents=results[query])

        browser.close()

    thread = Thread(target=run_search)
    thread.start()
    thread.join()

    return results`
  By changing the code inside the agent.py file in this way, I think it was solved playwright but there are other bugs. 

1-)The screenshot of the sites it searches does not appear 2) file[code] must be integer error 3-) does not follow the written plan in order and gets stuck

Ahmet0691 avatar Mar 27 '24 20:03 Ahmet0691

Hey @ARajgor, would you be able to resolve all the conflicts in this PR? Will merge this right away! πŸ™Œ

mufeedvh avatar Mar 28 '24 09:03 mufeedvh

Hey @ARajgor, would you be able to resolve all the conflicts in this PR? Will merge this right away! πŸ™Œ

have you reviewed the code and new changes?

ARajgor avatar Mar 28 '24 09:03 ARajgor

@ARajgor yes, it looks good to me even though it's a breaking change on almost all components. I might integrate some parts here and there to some changes I am working on myself. Will be posting in this thread as I work on it.

mufeedvh avatar Mar 28 '24 09:03 mufeedvh

@ARajgor yes, it looks good to me even though it's a breaking change on almost all components. I might integrate some parts here and there to some changes I am working on myself. Will be posting in this thread as I work on it.

okay. I'll do my best to resolve those. currently, I have my thoughts on this project and want to contribute more but right now I am pausing my development and finalizing the main branch.

also small request from my side, the discord server needs some structure. some people wanna help you out in managing the server.

ARajgor avatar Mar 28 '24 09:03 ARajgor

@ARajgor Just reviewed the PR, LGTM. Thank you! ❀️ πŸ™Œ

mufeedvh avatar Mar 31 '24 17:03 mufeedvh