Skip to content

Comment on Show HN: Lazer – library to expose Python functions to ChatGPT

Comments

Lazer is a Python library that provides a convenient way to expose Python functions as schemas for OpenAI chat models.

We're using OpenAI's new Function Calling API for this: <https://platform.openai.com/docs/guides/gpt/function-calling>.

We also made a demo called "gptbackdoor" that exposes a set of system functions for ChatGPT to call arbitrarily. It's in the `demo/` folder. Here's an example conversation:

  > What is in lazer/__init__.py
  < The `lazer/__init__.py` file contains the initialization of the `Lazer` and `LazerConversation` classes. 
  
  The `Lazer` class is responsible for managing the functions and their schemas. It initializes with an empty list of functions and a mapping of function names to functions. It also has methods to dispatch function calls, retrieve the list of functions, and add new functions to the list.
  
  The `LazerConversation` class represents a conversation with the `Lazer` instance. It initializes with an empty list of messages, a reference to the `Lazer` instance, and the chat completion arguments provided. It has a `talk` method that takes user input and uses the OpenAI Chat API to generate a response. The conversation messages and function calls are stored in the `self.messages` list.
  
  > Write a README for this code and write that into the README.md file.
  < I have written the README and saved it in the README.md file.

Theoretically, you can also expose a function that allows ChatGPT to talk to itself. However, we have tried this, and it ended up crashing due to infinite recursion.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.