Giter Site home page Giter Site logo

openaiclient's Introduction

OpenAI Client

This client was written to investigate the possibility of using Azure OpenAI service with the function call options.

At present it does not do much with function calls it will allow a conversation between a user and the AI whilst maintaining context in a very simple manner.

Running Tests

cargo test -- --test-threads=1 --nocapture

To Compile

Missing dependencies will be downloaded by cargo.

cargo build

Build release version:

cargo build --profile=release

Talking to AI with Client

Each message is sent to OpenAI instance in a JSON object (see the API documentation or the testing interface).

The application requires valid Azure authentication, these are provided in environment variables:

export AZURE_API_KEY=
export AZURE_API_BASE=
export AZURE_API_VERSION=

The history of the chat (to maintain context during a conversation with the AI agent) is stored in a JSON file located (by default in chats/) make sure this directory exists before executing the application (though the presence and permissions will be checked before calling the API so that an API call is not wasted. See openai::ChatContext::new_chat.

mkdir chats/

To execute the application with Cargo:

cargo run -- --write-req-resp 0001 "What is the most efficient way to search through a sorted list?"

To execute the application directly (release version):

target/release/openaiclient --write-req-resp 0001 "<as above>"

Chats are stored in the chats/ directory, after the first message the file 0001.json should be created containing the question and the response from GPT. The --write-req-resp option will save the data sent in last_request.json and last_response.json which will be created in the current directory.

Then provide a follow up question from a text file:

echo "Please provide some proof." >> followup.txt
cargo run -- 0001 @followup.txt

Executing Commands and Getting Results

Tools must be specified in the JSON requests sent to GPT. The datafunc/ directory contains a possible test chat template and can be used like this:

openaiclient --config-dir datafunc/ 1001 "What is the largest file in the current directory?"

The AI will use tools to perform tasks on the local computer, listing files, compiling code etc. This will be facilitated by tmux which can persist for more that one execution.

See Control Mode on tmux wiki

Known Working

This was compiled and working with:

rustc 1.71.1 (eb26296b5 2023-08-03) (Alpine Linux)

Alpine Linux release 3.18.6

References

openaiclient's People

Contributors

drcrane avatar

Watchers

 avatar

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.