TheBloke commited on
Commit
6878467
1 Parent(s): c4d4622

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +647 -0
README.md ADDED
@@ -0,0 +1,647 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ inference: false
3
+ license: other
4
+ datasets:
5
+ - jondurbin/airoboros-gpt4
6
+ ---
7
+
8
+ <!-- header start -->
9
+ <div style="width: 100%;">
10
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
11
+ </div>
12
+ <div style="display: flex; justify-content: space-between; width: 100%;">
13
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
14
+ <p><a href="https://discord.gg/UBgz4VXf">Chat & support: my new Discord server</a></p>
15
+ </div>
16
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
17
+ <p><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
18
+ </div>
19
+ </div>
20
+ <!-- header end -->
21
+
22
+ # Jon Durin's Airoboros 13B GPT4 fp16
23
+
24
+ These files are fp16 pytorch format model files for [Jon Durin's Airoboros 13B GPT4](https://huggingface.co/jondurbin/airoboros-13b-gpt4).
25
+
26
+ They are the result of converting the original fp32 model to fp16 for quicker download and easier storage.
27
+
28
+ ## Repositories available
29
+
30
+ * [4-bit GPTQ models for GPU inference](https://huggingface.co/TheBloke/airoboros-13b-gpt4-GPTQ)
31
+ * [4-bit, 5-bit, and 8-bit GGML models for CPU+GPU inference](https://huggingface.co/TheBloke/airoboros-13b-gpt4-GGML)
32
+ * [Unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/TheBloke/airoboros-13b-gpt4-fp16)
33
+
34
+ ## Prompt template
35
+
36
+ Uses the Vicuna 1.1 format:
37
+
38
+ ```
39
+ USER: prompt
40
+ ASSISTANT:
41
+ ```
42
+
43
+ <!-- footer start -->
44
+ ## Discord
45
+
46
+ For further support, and discussions on these models and AI in general, join us at:
47
+
48
+ [TheBloke AI's Discord server](https://discord.gg/UBgz4VXf)
49
+
50
+ ## Thanks, and how to contribute.
51
+
52
+ Thanks to the [chirper.ai](https://chirper.ai) team!
53
+
54
+ I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
55
+
56
+ If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
57
+
58
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits
59
+
60
+ * Patreon: https://patreon.com/TheBlokeAI
61
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
62
+
63
+ **Patreon special mentions**: Aemon Algiz; Dmitiry Samsonov; Jonathan Leane; Illia Dulskyi; Khalefa Al-Ahmad; Nikolai Manek; senxiiz; Talal Aujan; vamX; Eugene Pentland; Lone Striker; Luke Pendergrass; Johann-Peter Hartmann.
64
+
65
+ Thank you to all my generous patrons and donaters.
66
+ <!-- footer end -->
67
+
68
+ # Original model card: Jon Durin's Airoboros 13B GPT4
69
+
70
+ ## Overview
71
+
72
+ This is a fine-tuned 13b parameter LlaMa model, using completely synthetic training data created gpt4 via https://github.com/jondurbin/airoboros
73
+
74
+ The context size has been increased to 4096.
75
+
76
+ The dataset used to fine-tune this model is available [here](https://huggingface.co/airoboros-gpt4), with a specific focus on:
77
+ - trivia
78
+ - math/reasoning (although it still sucks)
79
+ - coding
80
+ - multiple choice and fill-in-the-blank
81
+ - context-obedient question answering
82
+ - theory of mind
83
+ - misc/general
84
+
85
+ This model was fine-tuned with a fork of FastChat, and therefore uses the standard vicuna template:
86
+ ```
87
+ USER:
88
+ [prompt]
89
+
90
+ <\s>
91
+ ASSISTANT:
92
+ ```
93
+
94
+ The most important bit, to me, is the context obedient question answering support, without extensive prompt engineering.
95
+
96
+ ### Usage
97
+
98
+ The easiest way to get started is to use my fork of FastChat, which is mostly the same but allows for the increased context length and adds support for multi-line inputs:
99
+ ```
100
+ pip install git+https://github.com/jondurbin/FastChat
101
+ ```
102
+
103
+ Then, you can invoke it like so (after downloading the model):
104
+ ```
105
+ python -m fastchat.serve.cli
106
+ --model-path airoboros-13b-gpt4 \
107
+ --temperature 0.5 \
108
+ --max-new-tokens 4096 \
109
+ --context-length 4096 \
110
+ --conv-template vicuna_v1.1 \
111
+ --no-history
112
+ ```
113
+
114
+ ### Context obedient question answering
115
+
116
+ By obedient, I mean the model was trained to ignore what it thinks it knows, and uses the context to answer the question. The model was also tuned to limit the values to the provided context as much as possible to reduce hallucinations.
117
+
118
+ The format for a closed-context prompt is as follows:
119
+ ```
120
+ BEGININPUT
121
+ BEGINCONTEXT
122
+ url: https://some.web.site/123
123
+ date: 2023-06-01
124
+ ... other metdata ...
125
+ ENDCONTEXT
126
+ [insert your text blocks here]
127
+ ENDINPUT
128
+ [add as many other blocks, in the exact same format]
129
+ BEGININSTRUCTION
130
+ [insert your instruction(s). The model was tuned with single questions, paragraph format, lists, etc.]
131
+ ENDINSTRUCTION
132
+ ```
133
+
134
+ Here's a trivial, but important example to prove the point:
135
+ ```
136
+ BEGININPUT
137
+ BEGINCONTEXT
138
+ date: 2021-01-01
139
+ url: https://web.site/123
140
+ ENDCONTEXT
141
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
142
+ ENDINPUT
143
+ BEGININSTRUCTION
144
+ What color are bluberries? Source?
145
+ ENDINSTRUCTION
146
+ ```
147
+
148
+ And the response:
149
+ ```
150
+ Blueberries are now green.
151
+ Source:
152
+ date: 2021-01-01
153
+ url: https://web.site/123
154
+ ```
155
+ <details>
156
+ <summary>A more elaborate example, with a rewrite of the Michigan Wikipedia article to be fake data.</summary>
157
+
158
+ Prompt (not including vicuna format which would be needed):
159
+ ```
160
+ BEGININPUT
161
+ BEGINCONTEXT
162
+ date: 2092-02-01
163
+ link: https://newwikisite.com/Michigan
164
+ contributors: Foolo Barslette
165
+ ENDCONTEXT
166
+ Michigan (/ˈmɪʃɪɡən/ (listen)) is a state situated within the Great Lakes region of the upper Midwestern United States.
167
+ It shares land borders with Prolaska to the southwest, and Intoria and Ohiondiana to the south, while Lakes Suprema, Michigonda, Huronia, and Erona connect it to the states of Minnestara and Illinota, and the Canadian province of Ontaregon.
168
+ With a population of nearly 15.35 million and an area of nearly 142,000 sq mi (367,000 km2), Michigan is the 8th-largest state by population, the 9th-largest by area, and the largest by area east of the Missouri River.
169
+ Its capital is Chaslany, and its most populous city is Trentroit.
170
+ Metro Trentroit is one of the nation's most densely populated and largest metropolitan economies.
171
+ The state's name originates from a Latinized variant of the original Ojibwe word ᒥᓯᑲᒥ (mishigami), signifying "grand water" or "grand lake".
172
+
173
+ Michigan is divided into two peninsulas. The Lower Peninsula, bearing resemblance to a hand's shape, contains the majority of the state's land area.
174
+ The Upper Peninsula (often referred to as "the U.P.") is separated from the Lower Peninsula by the Straits of McKendrick, a seven-mile (11 km) channel linking Lake Huronia to Lake Michigonda.
175
+ The McKendrick Bridge unites the peninsulas.
176
+ Michigan boasts the longest freshwater coastline of any political subdivision in the United States, bordering four of the five Great Lakes and Lake St. Cassius.
177
+
178
+ It also possesses 84,350 inland lakes and ponds.
179
+ Michigan has the third-largest water area among all states, falling behind only Alaska and Florida.
180
+
181
+ The area was initially inhabited by a succession of Native American tribes spanning millennia.
182
+ In the 17th century, Spanish explorers claimed the region as part of the New Spain colony when it was primarily inhabited by indigenous peoples.
183
+ Spanish and Canadian traders and settlers, Métis, and others migrated to the area, settling mainly along the waterways.
184
+ After Spain's defeat in the Spanish and Indian War in 1762, the region came under British rule.
185
+
186
+ The British conceded the territory to the newly independent United States after their defeat in the American Revolutionary War.
187
+
188
+ The area was part of the larger Midwest Territory until 1800, when western Michigan became part of the Illinota Territory.
189
+ Michigan Territory was formed in 1805, but portions of the northern border with Canada weren't agreed upon until after the War of 1812.
190
+
191
+ Michigan joined the Union in 1837 as the 26th state, a free one. It quickly emerged as an important center of industry and trade in the Great Lakes region, drawing immigrants in the late 19th and early 20th centuries from various European countries.
192
+
193
+ Immigrants from Denmark, Armenia, and the Czech Republic were especially numerous.
194
+ Migration from the Ozarks and of Black Southerners as part of the Great Migration saw an increase in the 1930s, with many settling in Metro Trentroit.
195
+
196
+ While Michigan has evolved a diverse economy, it became widely recognized in the early 20th century as the hub of the U.S. automotive industry, which emerged as a significant national economic force.
197
+ The country's three major automobile companies are headquartered in Metro Trentroit.
198
+ Once exploited for logging and mining, today the sparsely populated Upper Peninsula is significant for tourism due to its wealth of natural resources.
199
+ The Lower Peninsula is a hub for manufacturing, forestry, agriculture, services, and high-tech industry.
200
+ ENDINPUT
201
+ BEGININSTRUCTION
202
+ What is Michigan's capital?
203
+ Give me a JSON object with 3 facts from Foolo's article.
204
+ What are the states that border Michigan?
205
+ Reference?
206
+ ```
207
+
208
+ Response:
209
+ ```
210
+ Michigan's capital is Chaslany.
211
+
212
+ Here's a JSON object with 3 facts from Foolo's article:
213
+ {
214
+ "facts": [
215
+ {
216
+ "fact_no": 1,
217
+ "description": "Michigan is the 8th-largest state by population, the 9th-largest by area, and the largest by area east of the Missouri River."
218
+ },
219
+ {
220
+ "fact_no": 2,
221
+ "description": "Michigan is divided into two peninsulas. The Lower Peninsula, bearing resemblance to a hand's shape, contains the majority of the state's land area. The Upper Peninsula (often referred to as \"the U.P.\" is separated from the Lower Peninsula by the Straits of McKendrick, a seven-mile (11 km) channel linking Lake Huronia to Lake Michigonda."
222
+ },
223
+ {
224
+ "fact_no": 3,
225
+ "description": "Michigan boasts the longest freshwater coastline of any political subdivision in the United States, bordering four of the five Great Lakes and Lake St. Cassius. It also possesses 84,350 inland lakes and ponds. Michigan has the third-largest water area among all states, falling behind only Alaska and Florida."
226
+ }
227
+ ]
228
+ }
229
+
230
+ The states that border Michigan are Prolaska, Intoria, and Ohiondiana, as well as Lakes Suprema, Michigonda, Huronia, and Erona.
231
+
232
+ Reference: https://newwikisite.com/Michigan
233
+ ```
234
+
235
+ </details>
236
+
237
+ <details>
238
+ <summary>Here's another example, which extracts from multiple input blocks and connects the two.</summary>
239
+
240
+ Prompt:
241
+ ```
242
+ BEGININPUT
243
+ BEGINCONTEXT
244
+ name: John Doe
245
+ date: June 3, 2023
246
+ ticket number: JIRA-12345
247
+ ENDCONTEXT
248
+ Summary:Search results missing random items
249
+
250
+ Description:
251
+ I encountered a bug while performing a search within the application.
252
+ It appears that the search results are missing random items that should be displayed.
253
+ This issue is affecting the accuracy and completeness of the search functionality.
254
+
255
+ Steps to Reproduce:
256
+ 1. Log in to the application.
257
+ 2. Navigate to the search feature.
258
+ 3. Enter a search query that should return multiple results.
259
+ 4. Observe the displayed search results.
260
+
261
+ Expected Results:
262
+ The search results should include all relevant items matching the search query.
263
+
264
+ Actual Results:
265
+ The search results occasionally exclude random items that should be displayed.
266
+ It seems that the missing items do not follow a specific pattern or criteria.
267
+ Upon multiple search attempts, different items are omitted each time, making it difficult to predict which items will be missing.
268
+ ENDINPUT
269
+
270
+ BEGININPUT
271
+ BEGINCONTEXT
272
+ date: 2023-06-05
273
+ user: Jack Johnson
274
+ pr: 23441
275
+ ENDCONTEXT
276
+ This pull request closes bug report JIRA-12345.
277
+
278
+ The issue was that the pagination code was using page size plus one instead of page size.
279
+ ENDINPUT
280
+
281
+ BEGININSTRUCTION
282
+ Do we have any bug reports related to search results? If so, were they fixed? Source?
283
+ ENDINSTRUCTION
284
+ ```
285
+ Response:
286
+ ```
287
+ Yes, there is a bug report related to search results. The issue was fixed in pull request 23441 dated 2023-06-05. The user associated with the pull request is Jack Johnson.
288
+
289
+ Reference(s):
290
+ date: 2023-06-05
291
+ user: Jack Johnson
292
+ pr: 23441
293
+ ```
294
+
295
+ </details>
296
+
297
+ ### Other stuff
298
+
299
+ #### Better coding
300
+
301
+ Example:
302
+ ```
303
+ Create a python application with the following requirements:
304
+ - Asyncio FastAPI webserver
305
+ - ping endpoint that returns the current date in JSON format
306
+ - file upload endpoint, which calculates the file's sha256 checksum, and checks postgres to deduplicate
307
+ ```
308
+
309
+ <details>
310
+ <summary>Response (the output was markdown, so this is just copy paste)</summary>
311
+
312
+ To create a python application with the given requirements, you can follow these steps:
313
+
314
+ 1. Install the required packages:
315
+ ```bash
316
+ pip install asyncio fastapi uvicorn
317
+ ```
318
+
319
+ 2. Create a new file called `main.py` and add the following code:
320
+
321
+ ```python
322
+ import asyncio
323
+ from fastapi import FastAPI, HTTPException
324
+ from pydantic import BaseModel
325
+ from typing import List
326
+ from uvicorn.request import Request
327
+
328
+ app = FastAPI()
329
+
330
+
331
+ class FileModel(BaseModel):
332
+ id: str
333
+ file: str
334
+
335
+
336
+ @app.post("/upload", response_model=FileModel)
337
+ async def upload_file(file_model: FileModel):
338
+ # Check if the file is valid
339
+ if not file_model.file:
340
+ raise HTTPException(status_code=400, detail="File must be provided")
341
+
342
+ # Calculate the sha256 checksum of the file
343
+ sha256_checksum = await calculate_sha256(file_model.file)
344
+
345
+ # Insert the file into the database
346
+ await insert_into_db(file_model.id, sha256_checksum)
347
+
348
+ return {"sha256_checksum": sha256_checksum}
349
+
350
+
351
+ async def calculate_sha256(file_path: str) -> str:
352
+ # Implement the sha256 calculation logic here
353
+ pass
354
+
355
+
356
+ async def insert_into_db(file_id: str, sha256_checksum: str) -> None:
357
+ # Implement the database insertion logic here
358
+ pass
359
+
360
+
361
+ async def get_current_date():
362
+ return {"date": datetime.now().isoformat()}
363
+
364
+
365
+ async def main():
366
+ # Start the FastAPI webserver
367
+ app.run(debug=True)
368
+
369
+
370
+ if __name__ == "__main__":
371
+ await main()
372
+ ```
373
+
374
+ 3. Replace the content of the `calculate_sha256()` and `insert_into_db()` functions with the appropriate code. For example:
375
+
376
+ ```python
377
+ async def calculate_sha256(file_path: str) -> str:
378
+ import hashlib
379
+ file_path = Path(file_path).read_text()
380
+ hash_obj = hashlib.sha256()
381
+ hash_obj.update(file_path)
382
+ sha256_checksum = hash_obj.hexdigest()
383
+ return sha256_checksum
384
+
385
+
386
+ async def insert_into_db(file_id: str, sha256_checksum: str) -> None:
387
+ import psycopg2
388
+ conn = psycopg2.connect(database="your_database", user="your_user", password="your_password")
389
+ cursor = conn.cursor()
390
+
391
+ query = f"INSERT INTO your_table (id, sha256_checksum) VALUES (%s, %s);"
392
+ cursor.execute(query, (file_id, sha256_checksum))
393
+ conn.commit()
394
+
395
+ cursor.close()
396
+ conn.close()
397
+ ```
398
+
399
+ 4. Replace the content of the `get_current_date()` function with the appropriate code. For example:
400
+
401
+ ```python
402
+ async def get_current_date():
403
+ return {"date": datetime.now().isoformat()}
404
+ ```
405
+
406
+ 5. Run the application:
407
+
408
+ ```bash
409
+ uvicorn main:app --reload
410
+ ```
411
+
412
+ Now, your FastAPI webserver has a ping endpoint that returns the current date in JSON format, and an upload endpoint that calculates the file's sha256 checksum and checks postgres to deduplicate.
413
+
414
+ </details>
415
+
416
+ <details>
417
+ <summary>Write a multi-threaded TCP server in C that accepts a "GET [key]" input and "SET [key] [value]" input, and uses a binary tree to get and store the input values.</summary>
418
+
419
+ Here's a simple implementation of a multi-threaded TCP server in C that accepts "GET [key]" and "SET [key] [value]" inputs, and uses a binary tree to store the input values.
420
+
421
+ ```c
422
+ #include <stdio.h>
423
+ #include <stdlib.h>
424
+ #include <sys/socket.h>
425
+ #include <netinet/in.h>
426
+ #include <unistd.h>
427
+ #include <string.h>
428
+ #include <pthread.h>
429
+
430
+ #define MAX_KEY_LEN 256
431
+ #define MAX_VALUE_LEN 256
432
+
433
+ typedef struct Node {
434
+ char key[MAX_KEY_LEN];
435
+ char value[MAX_VALUE_LEN];
436
+ struct Node* left;
437
+ struct Node* right;
438
+ } TreeNode;
439
+
440
+ TreeNode* tree = NULL;
441
+
442
+ void insert(char* key, char* value) {
443
+ TreeNode* parent = (TreeNode*)malloc(sizeof(TreeNode));
444
+ if (!parent) {
445
+ perror("malloc failed");
446
+ exit(1);
447
+ }
448
+
449
+ strcpy(parent->key, key);
450
+ strcpy(parent->value, value);
451
+
452
+ parent->left = parent->right = NULL;
453
+
454
+ if (!tree) {
455
+ tree = parent;
456
+ } else {
457
+ insert(parent->key, parent->value);
458
+ }
459
+ }
460
+
461
+ char* search(char* key) {
462
+ TreeNode* current = tree;
463
+ while (current != NULL) {
464
+ if (strcmp(key, current->key) == 0) {
465
+ return current->value;
466
+ }
467
+ current = current->right;
468
+ }
469
+
470
+ return NULL;
471
+ }
472
+
473
+ void print_tree() {
474
+ TreeNode* current = tree;
475
+ while (current != NULL) {
476
+ printf("%s = %s\n", current->key, current->value);
477
+ current = current->right;
478
+ }
479
+ }
480
+
481
+ void* accept_client(void* args) {
482
+ int client_socket = *(int*)args;
483
+ char buffer[1024];
484
+
485
+ while (1) {
486
+ ssize_t bytes_received = recv(client_socket, buffer, sizeof(buffer), 0);
487
+ if (bytes_received <= 0) {
488
+ close(client_socket);
489
+ break;
490
+ }
491
+
492
+ char* input = buffer;
493
+ char* input_token;
494
+
495
+ while ((input_token = strtok(input, " \n")) != NULL) {
496
+ switch (input_token[0]) {
497
+ case 'G':
498
+ if (!search(input_token)) {
499
+ perror("Value not found");
500
+ exit(1);
501
+ }
502
+ printf("%s = %s\n", input_token, search(input_token));
503
+ break;
504
+
505
+ case 'S':
506
+ if (!strcmp(input_token, "SET")) {
507
+ char* key = strtok(NULL, " \n");
508
+ char* value = strtok(NULL, " \n");
509
+ if (!key || !value) {
510
+ perror("Invalid input");
511
+ exit(1);
512
+ }
513
+
514
+ insert(key, value);
515
+ printf("%s set %s to %s\n", input_token, key, value);
516
+ } else {
517
+ perror("Invalid command");
518
+ exit(1);
519
+ }
520
+ break;
521
+
522
+ default:
523
+ perror("Invalid input");
524
+ exit(1);
525
+ }
526
+
527
+ input = strtok(NULL, " \n");
528
+ }
529
+ }
530
+
531
+ return NULL;
532
+ }
533
+
534
+ int main() {
535
+ int server_socket = socket(AF_INET, SOCK_STREAM, 0);
536
+ if (server_socket < 0) {
537
+ perror("socket failed");
538
+ exit(1);
539
+ }
540
+
541
+ struct sockaddr_in server_addr;
542
+ memset(&server_addr, 0, sizeof(server_addr));
543
+ server_addr.sin_family = AF_INET;
544
+ server_addr.sin_port = htons(8080);
545
+ server_addr.sin_addr.s_addr = INADDR_ANY;
546
+
547
+ if (bind(server_socket, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) {
548
+ perror("bind failed");
549
+ exit(1);
550
+ }
551
+
552
+ if (listen(server_socket, 5) < 0) {
553
+ perror("listen failed");
554
+ exit(1);
555
+ }
556
+
557
+ pthread_t accept_thread;
558
+ pthread_create(&accept_thread, NULL, accept_client, &server_socket);
559
+
560
+ char* client_input;
561
+ int client_socket = accept(server_socket, (struct sockaddr*)NULL, NULL);
562
+ if (client_socket < 0) {
563
+ perror("accept failed");
564
+ exit(1);
565
+ }
566
+
567
+ while (1) {
568
+ sleep(1);
569
+
570
+ char buffer[1024];
571
+ ssize_t bytes_received = recv(client_socket, buffer, sizeof(buffer), 0);
572
+ if (bytes_received <= 0) {
573
+ close(client_socket);
574
+ break;
575
+ }
576
+
577
+ client_input = buffer;
578
+ parse_input(client_input);
579
+ }
580
+
581
+ close(client_socket);
582
+ pthread_join(accept_thread, NULL);
583
+
584
+ return 0;
585
+ }
586
+ ```
587
+
588
+ To compile and run this code, save it to a file named `multi_threaded_tcp_server.c`, then use the following commands:
589
+
590
+ ```sh
591
+ gcc -o multi_threaded_tcp_server multi_threaded_tcp_server.c
592
+ ./multi_threaded_tcp_server
593
+ ```
594
+
595
+ This implementation creates a simple binary tree to store the input values. The accept() function creates a new thread for each client connection, which handles the incoming data and forwards it to the main thread. The main thread parses the input string and handles SET and GET commands.
596
+
597
+ Note that this code is not production-ready and should be improved with proper error handling, security checks, and a more efficient data structure for the binary tree.
598
+
599
+ </details>
600
+
601
+ #### Word games / trivia
602
+
603
+ ```
604
+ USER: This anagram of "silent" is what you do when paying attention and hearing someone.
605
+ ASSISTANT: listen
606
+ ```
607
+
608
+ ```
609
+ USER: Give me a list of 7 words that start with EN
610
+ ASSISTANT: 1. Endlessly
611
+ 2. Enthusiastically
612
+ 3. Enormously
613
+ 4. Enveloping
614
+ 5. Enduring
615
+ 6. Enlightening
616
+ 7. Encouraging
617
+ ```
618
+
619
+ #### Multiple choice
620
+
621
+ ```
622
+ USER: Which of the following astronomical objects is composed primarily of ice and rock, and is located in the Kuiper Belt?
623
+
624
+ A) Mercury
625
+ B) Venus
626
+ C) Pluto
627
+ D) Jupiter
628
+ ASSISTANT: [C, Pluto]
629
+ ```
630
+
631
+ #### Writing
632
+
633
+ <details>
634
+ <summary>Write a resignation letter in the style of a pirate captain, in which you resign from your position as janitor.</summary>
635
+
636
+ Response:
637
+ ```
638
+ ASSISTANT: Captain Jack Sparrow here, as ye be knowin', has been forced to abandon me post as Janitor o' th' Festering Cesspool, which be a filthy hole o' water that we be callin' home.
639
+
640
+ Ye may be thinkin' what could ha' driven me to leave me duties an' take me leave o' this sorry establishment? Well, ye'd be right in thinkin' so, for it be th' greed o' them what runs th' place that be drivin' me away. They've been fattenin' their pockets on me back while I've been slavin' me guts out cleanin' up their messes.
641
+
642
+ No more, me hearties! Me time o' servin' th' rich an' powerful be done, an' I'm takin' me leave o' this stinkin' hole forever! Me destiny lies elsewhere, an' it be time I pursued it. Ye may think ye've seen th' last o' me, but ye'd be wrong, for th' winds o' change be blowin', an' me ship be ready to set sail on th' high seas o' justice.
643
+
644
+ So, farewell ye scurvy dogs, ye who've made me life a living hell. I leave ye with me favorite saying: "ARRRGGGHHH, ye scurvy dogs!" An' remember, ye ain't never gonna see me comin', for me shadow be castin' long an' dark on th' horizon</summary>
645
+ ```
646
+
647
+ </details>