Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benwills/simplegptapireq
Single file PHP + Curl class to send a single chat request to OpenAI, Anthropic, Gemini, or ollama.
https://github.com/benwills/simplegptapireq
anthropic chat-gpt chatgpt claude gemini gpt-api ollama open-ai openai
Last synced: 2 months ago
JSON representation
Single file PHP + Curl class to send a single chat request to OpenAI, Anthropic, Gemini, or ollama.
- Host: GitHub
- URL: https://github.com/benwills/simplegptapireq
- Owner: benwills
- Created: 2024-09-08T01:15:14.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-08T01:35:16.000Z (4 months ago)
- Last Synced: 2024-10-12T18:02:10.807Z (2 months ago)
- Topics: anthropic, chat-gpt, chatgpt, claude, gemini, gpt-api, ollama, open-ai, openai
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SimpleGptApiReq
Single file PHP + Curl class to send a _single_ chat request to OpenAI, Anthropic, Gemini, or ollama.
Use this if you're interested in a single, lightweight solution for querying the major GPT APIs. Or if you just want to understand better how the requests and responses happen.
There are still some bugs to work out. But it's the quickest and easiest solution that exists if you want to start using the APIs.
See example.php for a working example, which just requires you adding your API key(s). And if you want to use ollama, also adding the ollama root url.
```php
require_once(__DIR__.'/lib.SimpleGptApiReq.php');$req = new SimpleGptApiReq(
'model-name',
'api key',
'your gpt prompt'
);$rsp = $req->Exec(); // returns new SimpleGptApiReqRsp()
print_r($rsp);$resultText = $rsp->Data;
```To use ollama, just add your ollama api root url after 'your gpt prompt' above. eg:
```php
$req = new SimpleGptApiReq(
'ollama-model-name',
'ollama api key',
'your gpt prompt',
'ollama root url'
);$rsp = $req->Exec(); // returns new SimpleGptApiReqRsp()
print_r($rsp);$resultText = $rsp->Data;
```