Git Product home page Git Product logo

chapyter's People

Contributors

lolipopshock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chapyter's Issues

Uable to add use %chapyter openai_api_org = 'value'

Hi there, I want to configure the chapyter. However, when I use %chapyter openai_api_org = 'org-myorg', it's said that:

UsageError: Invalid usage of the chapyter command: openai_api_org = 'org-PrhJLJTejKb36yGXRldiR9RT'. It supports the following usage:

  • %chapyter
    print all the configurable parameters and its current value
  • %chapyter <parameter_name>
    print the current value of the parameter
  • %chapyter <parameter_name>=
    set the value of the parameter

Cannot connect to host api.openai.com:443 ssl:default

Traceback (most recent call last):
File "E:\anaconda\Lib\site-packages\aiohttp\connector.py", line 980, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\anaconda\Lib\asyncio\base_events.py", line 1085, in create_connection
raise exceptions[0]
File "E:\anaconda\Lib\asyncio\base_events.py", line 1069, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\anaconda\Lib\asyncio\base_events.py", line 973, in _connect_sock
await self.sock_connect(sock, address)
File "E:\anaconda\Lib\asyncio\selector_events.py", line 634, in sock_connect
return await fut
^^^^^^^^^
File "E:\anaconda\Lib\asyncio\futures.py", line 287, in await
yield self # This tells Task to wait for completion.
^^^^^^^^^^
File "E:\anaconda\Lib\asyncio\tasks.py", line 339, in __wakeup
future.result()
File "E:\anaconda\Lib\asyncio\futures.py", line 203, in result
raise self._exception.with_traceback(self._exception_tb)
File "E:\anaconda\Lib\asyncio\selector_events.py", line 674, in _sock_connect_cb
raise OSError(err, f'Connect call failed {address}')
TimeoutError: [Errno 10060] Connect call failed ('199.59.148.6', 443)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\openai\api_requestor.py", line 668, in arequest_raw
result = await session.request(**request_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\anaconda\Lib\site-packages\aiohttp\client.py", line 536, in _request
conn = await self._connector.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\anaconda\Lib\site-packages\aiohttp\connector.py", line 540, in connect
proto = await self._create_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\anaconda\Lib\site-packages\aiohttp\connector.py", line 901, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\anaconda\Lib\site-packages\aiohttp\connector.py", line 1206, in _create_direct_connection
raise last_exc
File "E:\anaconda\Lib\site-packages\aiohttp\connector.py", line 1175, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\anaconda\Lib\site-packages\aiohttp\connector.py", line 988, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.openai.com:443 ssl:default [Connect call failed ('199.59.148.6', 443)]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 109, in run
await self.visit(self.parse_tree, VariableStack([self.program._variables], self))
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 559, in visit
visited_children.append(await self.visit(child, variable_stack, inner_next_node, inner_next_next_node, inner_prev_node, node, parent_node))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 524, in visit
command_output = await command_function(*positional_args, **named_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance\library_assistant.py", line 13, in assistant
return await role(role_name="assistant", hidden=hidden, _parser_context=_parser_context, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance\library_role.py", line 17, in role
new_content += await parser.visit(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 559, in visit
visited_children.append(await self.visit(child, variable_stack, inner_next_node, inner_next_next_node, inner_prev_node, node, parent_node))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 559, in visit
visited_children.append(await self.visit(child, variable_stack, inner_next_node, inner_next_next_node, inner_prev_node, node, parent_node))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 266, in visit
visited_children = [await self.visit(child, variable_stack, next_node, next_next_node, prev_node, node, parent_node) for child in node]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 266, in
visited_children = [await self.visit(child, variable_stack, next_node, next_next_node, prev_node, node, parent_node) for child in node]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance_program_executor.py", line 379, in visit
command_output = await command_function(*positional_args, **named_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance\library_gen.py", line 140, in gen
gen_obj = await parser.llm_session(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance\llms_openai.py", line 665, in call
out = await self.llm.caller(**call_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\guidance\llms_openai.py", line 370, in _library_call
out = await openai.ChatCompletion.acreate(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\openai\api_resources\chat_completion.py", line 45, in acreate
return await super().acreate(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 217, in acreate
response, _, api_key = await requestor.arequest(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\openai\api_requestor.py", line 372, in arequest
result = await self.arequest_raw(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\63268\AppData\Roaming\Python\Python311\site-packages\openai\api_requestor.py", line 685, in arequest_raw
raise error.APIConnectionError("Error communicating with OpenAI") from e
openai.error.APIConnectionError: Error communicating with OpenAI

Error in program: Error communicating with OpenAI

KeyError: 'Could not automatically map gpt-4 to a tokeniser. Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect.'

I tried a basic test of chapyter but it errors:

%load_ext chapyter

%%chat
hello

Trace:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[2], line 1
----> 1 get_ipython().run_cell_magic('chat', '', '\nhello\n')

File ~/miniconda/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2430, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
   2428 with self.builtin_trap:
   2429     args = (magic_arg_s, cell)
-> 2430     result = fn(*args, **kwargs)
   2432 # The code below prevents the output from being displayed
   2433 # when using magics with decodator @output_can_be_silenced
   2434 # when the last Python token in the expression is a ';'.
   2435 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/miniconda/lib/python3.10/site-packages/chapyter/magic.py:183, in Chapyter.chat(self, line, cell)
    180     return
    181 current_message = cell
--> 183 program_out = self.agent.execute_chat(current_message, args, self.shell)
    184 execution_id = self.shell.execution_count
    185 program_out = f"# Assistant Code for Cell [{execution_id}]:\n" + program_out

File ~/miniconda/lib/python3.10/site-packages/chapyter/magic.py:114, in ChapyterAgent.execute_chat(self, message, args, shell, **kwargs)
    106 def execute_chat(
    107     self,
    108     message: str,
   (...)
    111     **kwargs,
    112 ):
    113     program = self.get_program(args, kwargs.get("chatonly", False))
--> 114     llm = self.load_model(args, program)
    116     response = program.execute(
    117         message=message,
    118         llm=llm,
   (...)
    121         **kwargs,
    122     )
    123     return response

File ~/miniconda/lib/python3.10/site-packages/chapyter/magic.py:74, in ChapyterAgent.load_model(self, args, program)
     71 if program.model_name is not None:
     72     model_name = program.model_name
---> 74 return self._load_model(model_name)

File ~/miniconda/lib/python3.10/site-packages/chapyter/magic.py:61, in ChapyterAgent._load_model(self, model_name)
     60 def _load_model(self, model_name: Optional[str]) -> guidance.llms.LLM:
---> 61     model = guidance.llms.OpenAI(
     62         model_name, organization=os.environ["OPENAI_ORGANIZATION"]
     63     )
     64     # TODO: Support Azure models
     65     return model

File ~/miniconda/lib/python3.10/site-packages/guidance/llms/_openai.py:178, in OpenAI.__init__(self, model, caching, max_retries, max_calls_per_min, api_key, api_type, api_base, api_version, deployment_id, temperature, chat_mode, organization, rest_call, allowed_special_tokens, token, endpoint)
    175     api_base = os.environ.get("OPENAI_API_BASE", None) or os.environ.get("OPENAI_ENDPOINT", None) # ENDPOINT is deprecated
    177 import tiktoken
--> 178 self._tokenizer = tiktoken.get_encoding(tiktoken.encoding_for_model(model).name)
    179 self.chat_mode = chat_mode
    181 self.allowed_special_tokens = allowed_special_tokens

File ~/miniconda/lib/python3.10/site-packages/tiktoken/model.py:68, in encoding_for_model(model_name)
     65             return get_encoding(model_encoding_name)
     67 if encoding_name is None:
---> 68     raise KeyError(
     69         f"Could not automatically map {model_name} to a tokeniser. "
     70         "Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect."
     71     ) from None
     73 return get_encoding(encoding_name)

KeyError: 'Could not automatically map gpt-4 to a tokeniser. Please use `tiktok.get_encoding` to explicitly get the tokeniser you expect.'

No output in JetBrains IDEs

There's no output appearing when used in the Notebook UI in any of the JetBrains IDEs. I assume this is related to #24 but just noting here in case it needs to be handled separately.

Error communicating with OpenAI when use proxy.

Why can’t the server be accessed using a proxy?

The exception msg:
image

The https proxy has already been set in the proxy settings, as follows:
image

Other test programs can responsed normally by directly calling the API using request, as follows:
image

Can anyone help solve this problem? Thanks so much~~

No output in Google Colab

I'm trying to run Chapyter in Google Colab. After installing with pip and setting the api keys,
the %load_ext chapyter works, but when I try to run something with %chat, the command returns no output.

Why is %load_ext necessary?

This may be a Python or Jupyter question but I've never encountered this before with an extension so just asking here in case it's related. Why do I need %load_ext chapyter? I've used lots of extensions and have never encountered the need for %load_ext before. Most (all) load automatically just by being installed with pip.

Environment variable OPEN_AI_KEY not found by

I'm running JupyterLab 4.0.4 on a Mac and trying to use Chapyter.
I have an environment variable OPEN_AI_KEY set and can check this by: echo $OPENAI_API_KEY

Chapyter is installed and in my first cell I have:

%load_ext chapyter

And then:

%%chat
add numbers from 1 to 10

I get this error:
assert openai.api_key is not None, "You must provide an OpenAI API key to use the OpenAI LLM. Either pass it in the constructor, set the OPENAI_API_KEY environment variable, or create the file ~/.openai_api_key with your key in it."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.