This is my new version, using Langchain and OpenAI functions to return exact format
A library to use with NodeJS to use AI Function and return the wanted output. Check the example to understand the usage
https://github.com/Clad3815/ai-function-helper-langchain/
aiFunction Helper for Langchain
This module utilizes OpenAI Functions to yield outputs that match a specified format for any provided prompt. It transforms an input schema into an OpenAI function, which is then invoked by OpenAI to return a response in the correct format.
Why use this script instead of the normal OpenAI API?
While the OpenAI API is powerful and versatile, it can sometimes be challenging to get the desired response format, especially when integrating the output directly into other functions within your application. Crafting the perfect prompt might require multiple iterations, and even then, the returned response may need additional processing.
The aiFunction script is designed to simplify this process and provide a more streamlined experience for developers. By using this script, you can:
-
Get precise response formats:
aiFunctionallows you to specify the exact format of the response, such as lists, dictionaries, or strings, which can be used directly by other functions within your application without the need for additional processing. -
Avoid complex prompt crafting: With
aiFunction, you don't need to spend time crafting complex prompts or over-explaining the desired output to the API. The script takes care of constructing the prompt based on the provided function name, arguments, and description. -
Simplify integration: By leveraging
aiFunction, you can seamlessly integrate AI-generated content into your application, reducing the amount of code needed to parse and process the API's response. -
Increased security against prompt hijacking: When using
aiFunction, it is more difficult for the AI model to be hijacked with unexpected instructions. The separation of the description and arguments inaiFunctionprovides better context for the AI model and helps maintain focus on the intended task. Additionally, the optional hijack protection feature ensures that any hijacking instructions are treated as normal text, adding an extra layer of security to your application. -
Better data and prompt understanding:
aiFunctionhelps the AI model to better understand the data and the prompt by providing a clear separation between them. This clear distinction allows the AI to better focus on the intended task and reduces the risk of confusion when processing data inside the prompt.
In summary, the aiFunction script offers a more efficient and convenient way of interacting with the OpenAI API, enabling you to focus on integrating AI-generated content into your application without worrying about prompt crafting, response formatting, and security concerns.