Skip to content

Commit

Permalink
Use fetch as a prefix rather than suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Mar 9, 2024
1 parent 0ddcaac commit b01e7a1
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Particular useful are:
* multi-shot prompts for systems not yet supported
(see the [ai-cli-config](src/ai-cli-config) file),
* support for other large language models
(start from the [OpenAI_fetch.c](src/openai_fetch.c) file),
(start from the [openai_fetch.c](src/openai_fetch.c) file),
* support for other libraries (mainly [editline](https://man.netbsd.org/editline.3)),
* ports to other platforms and distributions.

Expand Down
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ MANPREFIX ?= "$(PREFIX)/share/man/"
SHAREPREFIX ?= "$(PREFIX)/share/ai-cli"

PROGS=rl_driver $(SHARED_LIB)
RL_SRC=ai_cli.c config.c ini.c anthropic_fetch.c openai_fetch.c \
llamacpp_fetch.c support.c
RL_SRC=ai_cli.c config.c ini.c fetch_anthropic.c fetch_openai.c \
fetch_llamacpp.c support.c
TEST_SRC=$(wildcard *_test.c)
LIB=-lcurl -ljansson

Expand Down
14 changes: 7 additions & 7 deletions src/ai_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

#include "config.h"

#include "anthropic_fetch.h"
#include "llamacpp_fetch.h"
#include "openai_fetch.h"
#include "fetch_anthropic.h"
#include "fetch_llamacpp.h"
#include "fetch_openai.h"

/*
* Dynamically obtained pointer to readline(3) variables..
Expand All @@ -47,7 +47,7 @@ static int *history_length_ptr;
// Loaded configuration
static config_t config;

// API fetch function, e.g. openai_fetch or llamacpp_fetch
// API fetch function, e.g. fetch_openai or fetch_llamacpp

char * (*fetch)(config_t *config, const char *prompt, int history_length);

Expand Down Expand Up @@ -132,16 +132,16 @@ setup(void)
REQUIRE(general, api);

if (strcmp(config.general_api, "openai") == 0) {
fetch = openai_fetch;
fetch = fetch_openai;
REQUIRE(openai, key);
REQUIRE(openai, endpoint);
} else if (strcmp(config.general_api, "anthropic") == 0) {
fetch = anthropic_fetch;
fetch = fetch_anthropic;
REQUIRE(anthropic, key);
REQUIRE(anthropic, endpoint);
REQUIRE(anthropic, version);
} else if (strcmp(config.general_api, "llamacpp") == 0) {
fetch = llamacpp_fetch;
fetch = fetch_llamacpp;
REQUIRE(llamacpp, endpoint);
} else {
fprintf(stderr, "Unsupported API: [%s].\n", config.general_api);
Expand Down
4 changes: 2 additions & 2 deletions src/anthropic_fetch.c → src/fetch_anthropic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "config.h"
#include "support.h"
#include "anthropic_fetch.h"
#include "fetch_anthropic.h"

// HTTP headers
static char *key_header;
Expand Down Expand Up @@ -84,7 +84,7 @@ initialize(config_t *config)
* Provide context in the form of n-shot prompts and history prompts.
*/
char *
anthropic_fetch(config_t *config, const char *prompt, int history_length)
fetch_anthropic(config_t *config, const char *prompt, int history_length)
{
CURLcode res;

Expand Down
2 changes: 1 addition & 1 deletion src/anthropic_fetch.h → src/fetch_anthropic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
#include "config.h"

char *anthropic_get_response_content(const char *json_response);
char *anthropic_fetch(config_t *config, const char *prompt, int history_length);
char *fetch_anthropic(config_t *config, const char *prompt, int history_length);
2 changes: 1 addition & 1 deletion src/anthropic_fetch_test.c → src/fetch_anthropic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#include "CuTest.h"
#include "anthropic_fetch.h"
#include "fetch_anthropic.h"

static const char json_response[] = "{"
" \"content\": ["
Expand Down
4 changes: 2 additions & 2 deletions src/llamacpp_fetch.c → src/fetch_llamacpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "config.h"
#include "support.h"
#include "llamacpp_fetch.h"
#include "fetch_llamacpp.h"

// Return the response content from a llama.cpp JSON response
STATIC char *
Expand Down Expand Up @@ -96,7 +96,7 @@ prompt_append(struct string *s, const char *role, const char *prompt)
* Provide context in the form of n-shot prompts and history prompts.
*/
char *
llamacpp_fetch(config_t *config, const char *prompt, int history_length)
fetch_llamacpp(config_t *config, const char *prompt, int history_length)
{
CURLcode res;

Expand Down
2 changes: 1 addition & 1 deletion src/llamacpp_fetch.h → src/fetch_llamacpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
#include "config.h"

char *llamacpp_get_response_content(const char *json_response);
char *llamacpp_fetch(config_t *config, const char *prompt, int history_length);
char *fetch_llamacpp(config_t *config, const char *prompt, int history_length);
2 changes: 1 addition & 1 deletion src/llamacpp_fetch_test.c → src/fetch_llamacpp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#include "CuTest.h"
#include "llamacpp_fetch.h"
#include "fetch_llamacpp.h"

static const char json_response[] = "{"
" \"content\": \"Assistant: shutdown -h now\","
Expand Down
2 changes: 1 addition & 1 deletion src/openai_fetch.c → src/fetch_openai.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ initialize(config_t *config)
* Provide context in the form of n-shot prompts and history prompts.
*/
char *
openai_fetch(config_t *config, const char *prompt, int history_length)
fetch_openai(config_t *config, const char *prompt, int history_length)
{
CURLcode res;

Expand Down
2 changes: 1 addition & 1 deletion src/openai_fetch.h → src/fetch_openai.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
#include "config.h"

char *openai_get_response_content(const char *json_response);
char *openai_fetch(config_t *config, const char *prompt, int history_length);
char *fetch_openai(config_t *config, const char *prompt, int history_length);
2 changes: 1 addition & 1 deletion src/openai_fetch_test.c → src/fetch_openai_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#include "CuTest.h"
#include "openai_fetch.h"
#include "fetch_openai.h"

static const char json_response[] = "{\n"
" \"id\": \"chatcmpl-7lg1IuegIknbhVaP00yWmdOeCeWi1\",\n"
Expand Down

0 comments on commit b01e7a1

Please sign in to comment.