Skip to content

Commit c178d7a

Browse files
committed
Add HAL 9000 API
1 parent 0e26f2d commit c178d7a

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

src/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MANPREFIX ?= "$(PREFIX)/share/man/"
66
SHAREPREFIX ?= "$(PREFIX)/share/ai-cli"
77

88
PROGS=rl_driver $(SHARED_LIB)
9-
RL_SRC=ai_cli.c config.c ini.c fetch_anthropic.c fetch_openai.c \
9+
RL_SRC=ai_cli.c config.c ini.c fetch_anthropic.c fetch_hal.c fetch_openai.c \
1010
fetch_llamacpp.c support.c
1111
TEST_SRC=$(wildcard *_test.c)
1212
LIB=-lcurl -ljansson

src/ai_cli.5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ It can be used when Emacs key bindings are in effect.
7979
.PP
8080
\fIapi=\fR
8181
.RS 4
82-
Specify the API to use: one of anthropic, llamacpp, or openai.
82+
Specify the API to use: one of anthropic, hal, llamacpp, or openai.
8383
.RE
8484

8585
.PP

src/ai_cli.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "config.h"
3131

3232
#include "fetch_anthropic.h"
33+
#include "fetch_hal.h"
3334
#include "fetch_llamacpp.h"
3435
#include "fetch_openai.h"
3536

@@ -140,6 +141,8 @@ setup(void)
140141
REQUIRE(anthropic, key);
141142
REQUIRE(anthropic, endpoint);
142143
REQUIRE(anthropic, version);
144+
} else if (strcmp(config.general_api, "hal") == 0) {
145+
fetch = fetch_hal;
143146
} else if (strcmp(config.general_api, "llamacpp") == 0) {
144147
fetch = fetch_llamacpp;
145148
REQUIRE(llamacpp, endpoint);

src/fetch_hal.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*-
2+
*
3+
* ai-cli - readline wrapper to obtain a generative AI suggestion
4+
* Dummy HAL 9000 access function, that can be used for testing.
5+
*
6+
* Copyright 2024 Diomidis Spinellis
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#include "config.h"
22+
#include "fetch_hal.h"
23+
24+
/*
25+
* Fetch response from the dummy HAL 9000 API.
26+
* See https://en.wikipedia.org/wiki/HAL_9000 and
27+
* https://en.wikiquote.org/wiki/2001:_A_Space_Odyssey_(film).
28+
* This endpoint can be used for testing the ai-cli-lib functionality
29+
* without the need to use a networked API.
30+
*/
31+
char *
32+
fetch_hal(config_t *config, const char *prompt, int history_length)
33+
{
34+
return "# I'm sorry, Dave. I'm afraid I can't do that.";
35+
}

src/fetch_hal.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*-
2+
*
3+
* ai-cli - readline wrapper to obtain a generative AI suggestion
4+
* Dummy HAL 9000 access function, that can be used for testing.
5+
*
6+
* Copyright 2023 Diomidis Spinellis
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#include "config.h"
22+
23+
char *fetch_hal(config_t *config, const char *prompt, int history_length);

0 commit comments

Comments
 (0)