lion-agi / lionagi

An AGentic Intelligence Operating System
https://lionagi.ai
Apache License 2.0
281 stars 54 forks source link

RuntimeError +house keeping #I am rather shit at coding #143

Closed hashhac closed 8 months ago

hashhac commented 9 months ago

=>some issues =>quick start code needs import asyncio to use await function inside # run a LLM API call ===> RuntimeError: no running event loop error you're seeing. That error is happening because the lionagi library is trying to create an asyncio task at import time, which is generally not a good practice because the asyncio event loop is not running at that point. =>Python 3.9 or higher. on github is incorrect it doesn't run on python 3.12.0 (I think you covered this in discord already)=> https://www.python.org/downloads/release/python-390/ => It would be nice if it said on github you needed the dependency packages installed => pip install python-dotenv httpx tiktoken aiohttp => love the project sorry if something here is wrong.

Context => on lion-agi discord: Hello I am rather shit at coding but am working on it so please no hate: I was trying to run your quick start code without making a call to a model just to see if it works i know this isnt the intended use for it. The first thing is that i got errors for not having import asyncio. Then it threw a bunch of errors. Plugging them into copilot => gave me this However, this won't fix the RuntimeError: no running event loop error you're seeing. That error is happening because the lionagi library is trying to create an asyncio task at import time, which is generally not a good practice because the asyncio event loop is not running at that point. <= i get 50% of this but yea idk if this is even a bug uhm i think i will set up a local model and then test on that in the future should be fun :D. side note dont think it matters but it works in interactive window not sure why. Anyway love the project 🙂 =>Reply ah i see, thank you for bringing it up, the problem is probably caused by we primarily test our package in an interactive env like ipynb. if you don't mind, please add an issue

ohdearquant commented 9 months ago

yey, first community raised issue!! we will look into this, probably won't be able to fix in next release though

ohdearquant commented 9 months ago

fixed, will update in 0.0.111

fengyunzaidushi commented 8 months ago

python:3.10.11 lionagi: 0.0.112 system:ubuntu22.04

i sitll have the problem when i run the code in the readme. I changed the code and if I didn't change it, I'd get an error

import lionagi as li
import asyncio
# define system messages, context and user instruction
system = "You are a helpful assistant designed to perform calculations."
instruction = {"Addition":"Add the two numbers together i.e. x+y"}
context = {"x": 10, "y": 5}

# Initialize a session with a system message
calculator = li.Session(system=system)

# 使用 async def 定义一个异步函数
async def some_async_function():
    result = await calculator.initiate(instruction=instruction)
    # 对 result 进行处理
    print(f"Calculation Result: {result}")

# 然后在事件循环中运行这个异步函数
asyncio.run(some_async_function())

but still i got the error:

Traceback (most recent call last):
  File "/mnt/sda/github/12yue/lionagi/ceshi.py", line 1, in <module>
    import lionagi as li
  File "/mnt/sda/github/12yue/lionagi/lionagi/__init__.py", line 24, in <module>
    from .core import *
  File "/mnt/sda/github/12yue/lionagi/lionagi/core/__init__.py", line 3, in <module>
    from .sessions import Session
  File "/mnt/sda/github/12yue/lionagi/lionagi/core/sessions.py", line 13, in <module>
    OAIService = OpenAIService()
  File "/mnt/sda/github/12yue/lionagi/lionagi/services.py", line 22, in __init__
    super().__init__(
  File "/mnt/sda/github/12yue/lionagi/lionagi/service_/base_service.py", line 142, in __init__
    self.rate_limiter = ratelimiter(max_requests_per_minute, max_tokens_per_minute)
  File "/mnt/sda/github/12yue/lionagi/lionagi/service_/base_service.py", line 18, in __init__
    self.rate_limit_replenisher_task = asyncio.create_task(self.rate_limit_replenisher())
  File "/opt/miniconda3/envs/py310_chat/lib/python3.10/asyncio/tasks.py", line 336, in create_task
    loop = events.get_running_loop()
RuntimeError: no running event loop
sys:1: RuntimeWarning: coroutine 'BaseAPIRateLimiter.rate_limit_replenisher' was never awaited
ohdearquant commented 8 months ago

in the new version, we did major restructuring, and didn't test in non-interactive environment yet, will have another fix on it soon.

fengyunzaidushi commented 8 months ago

ok,thanks.

i find the lionagi==0.0.111 is ok,but still ,should modify the readme.md code to this ,then i will work:

import lionagi as li
import asyncio
# define system messages, context and user instruction
system = "You are a helpful assistant designed to perform calculations."
instruction = {"Addition":"Add the two numbers together i.e. x+y"}
context = {"x": 10, "y": 5}

# Initialize a session with a system message
calculator = li.Session(system=system)

# 使用 async def 定义一个异步函数
async def some_async_function():
    result = await calculator.initiate(instruction=instruction,
                                       context=context,
                                       model="gpt-4-1106-preview",)
    # 对 result 进行处理
    print(f"Calculation Result: {result}")

# 然后在事件循环中运行这个异步函数
asyncio.run(some_async_function())
ohdearquant commented 8 months ago

Thanks, we will dig into it

ohdearquant commented 8 months ago

this problem should be solved in 0.0.113, you will need to do dotenv.load_dotenv ()