jondurbin commited on
Commit
1140002
1 Parent(s): c3dd97f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +616 -0
README.md CHANGED
@@ -1,3 +1,619 @@
1
  ---
2
  license: other
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: other
3
+ datasets:
4
+ - jondurbin/airoboros-gpt4
5
  ---
6
+
7
+ ## Delta 1.1
8
+
9
+ This is a minor update of https://huggingface.co/jondurbin/airoboros-7b-gpt4 with ~1k more coding instructions, and fixes/improvements to context instructions from https://huggingface.co/datasets/jondurbin/airoboros-gpt4-1.1
10
+
11
+ The remainder of the model card is duplicated from the origin.
12
+
13
+ ## Overview
14
+
15
+ This is a fine-tuned 7b parameter LlaMa model, using completely synthetic training data created gpt4 via https://github.com/jondurbin/airoboros
16
+
17
+ The dataset used to fine-tune this model is available [here](https://huggingface.co/datasets/jondurbin/airoboros-gpt4-1.1), with a specific focus on:
18
+ - trivia
19
+ - math/reasoning (although it still sucks)
20
+ - coding
21
+ - multiple choice and fill-in-the-blank
22
+ - context-obedient question answering
23
+ - theory of mind
24
+ - misc/general
25
+
26
+ This model was fine-tuned with a fork of FastChat, and therefore uses the standard vicuna template:
27
+ ```
28
+ USER: [prompt] ASSISTANT:
29
+ ```
30
+
31
+ The most important bit, to me, is the context obedient question answering support, without extensive prompt engineering.
32
+
33
+ ### Usage
34
+
35
+ 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:
36
+ ```
37
+ pip install git+https://github.com/jondurbin/FastChat
38
+ ```
39
+
40
+ Then, you can invoke it like so (after downloading the model):
41
+ ```
42
+ python -m fastchat.serve.cli
43
+ --model-path airoboros-13b-gpt4 \
44
+ --temperature 0.5 \
45
+ --max-new-tokens 4096 \
46
+ --conv-template vicuna_v1.1 \
47
+ --no-history
48
+ ```
49
+
50
+ ### Context obedient question answering
51
+
52
+ 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.
53
+
54
+ The format for a closed-context prompt is as follows:
55
+ ```
56
+ BEGININPUT
57
+ BEGINCONTEXT
58
+ url: https://some.web.site/123
59
+ date: 2023-06-01
60
+ ... other metdata ...
61
+ ENDCONTEXT
62
+ [insert your text blocks here]
63
+ ENDINPUT
64
+ [add as many other blocks, in the exact same format]
65
+ BEGININSTRUCTION
66
+ [insert your instruction(s). The model was tuned with single questions, paragraph format, lists, etc.]
67
+ ENDINSTRUCTION
68
+ ```
69
+
70
+ It's also helpful to add "Don't make up answers if you don't know." to your instruction block to make sure if the context is completely unrelated it doesn't make something up.
71
+
72
+ *The __only__ prompts that need this closed context formating are closed-context instructions. Normal questions/instructions do not!*
73
+
74
+ I know it's a bit verbose and annoying, but after much trial and error, using these explicit delimiters helps the model understand where to find the responses and how to associate specific sources with it.
75
+ - `BEGININPUT` - denotes a new input block
76
+ - `BEGINCONTEXT` - denotes the block of context (metadata key/value pairs) to associate with the current input block
77
+ - `ENDCONTEXT` - denotes the end of the metadata block for the current input
78
+ - [text] - Insert whatever text you want for the input block, as many paragraphs as can fit in the context.
79
+ - `ENDINPUT` - denotes the end of the current input block
80
+ - [repeat as many input blocks in this format as you want]
81
+ - `BEGININSTRUCTION` - denotes the start of the list (or one) instruction(s) to respond to for all of the input blocks above.
82
+ - [instruction(s)]
83
+ - `ENDINSTRUCTION` - denotes the end of instruction set
84
+
85
+ It sometimes works without `ENDINSTRUCTION`, but by explicitly including that in the prompt, the model better understands that all of the instructions in the block should be responded to.
86
+
87
+ Here's a trivial, but important example to prove the point:
88
+ ```
89
+ BEGININPUT
90
+ BEGINCONTEXT
91
+ date: 2021-01-01
92
+ url: https://web.site/123
93
+ ENDCONTEXT
94
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
95
+ ENDINPUT
96
+ BEGININSTRUCTION
97
+ What color are bluberries? Source?
98
+ ENDINSTRUCTION
99
+ ```
100
+
101
+ And the response:
102
+ ```
103
+ Blueberries are now green.
104
+ Source:
105
+ date: 2021-01-01
106
+ url: https://web.site/123
107
+ ```
108
+
109
+ The prompt itself should be wrapped in the vicuna1.1 template if you aren't using fastchat with the conv-template vicuna_v1.1 as described:
110
+
111
+ ```
112
+ USER: BEGININPUT
113
+ BEGINCONTEXT
114
+ date: 2021-01-01
115
+ url: https://web.site/123
116
+ ENDCONTEXT
117
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
118
+ ENDINPUT
119
+ BEGININSTRUCTION
120
+ What color are bluberries? Source?
121
+ ENDINSTRUCTION
122
+ ASSISTANT:
123
+ ```
124
+
125
+ <details>
126
+ <summary>A more elaborate example, with a rewrite of the Michigan Wikipedia article to be fake data.</summary>
127
+
128
+ Prompt (not including vicuna format which would be needed):
129
+ ```
130
+ BEGININPUT
131
+ BEGINCONTEXT
132
+ date: 2092-02-01
133
+ link: https://newwikisite.com/Michigan
134
+ contributors: Foolo Barslette
135
+ ENDCONTEXT
136
+ Michigan (/ˈmɪʃɪɡən/ (listen)) is a state situated within the Great Lakes region of the upper Midwestern United States.
137
+ 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.
138
+ 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.
139
+ Its capital is Chaslany, and its most populous city is Trentroit.
140
+ Metro Trentroit is one of the nation's most densely populated and largest metropolitan economies.
141
+ The state's name originates from a Latinized variant of the original Ojibwe word ᒥᓯᑲᒥ (mishigami), signifying "grand water" or "grand lake".
142
+
143
+ 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.
144
+ 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.
145
+ The McKendrick Bridge unites the peninsulas.
146
+ 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.
147
+
148
+ It also possesses 84,350 inland lakes and ponds.
149
+ Michigan has the third-largest water area among all states, falling behind only Alaska and Florida.
150
+
151
+ The area was initially inhabited by a succession of Native American tribes spanning millennia.
152
+ In the 17th century, Spanish explorers claimed the region as part of the New Spain colony when it was primarily inhabited by indigenous peoples.
153
+ Spanish and Canadian traders and settlers, Métis, and others migrated to the area, settling mainly along the waterways.
154
+ After Spain's defeat in the Spanish and Indian War in 1762, the region came under British rule.
155
+
156
+ The British conceded the territory to the newly independent United States after their defeat in the American Revolutionary War.
157
+
158
+ The area was part of the larger Midwest Territory until 1800, when western Michigan became part of the Illinota Territory.
159
+ Michigan Territory was formed in 1805, but portions of the northern border with Canada weren't agreed upon until after the War of 1812.
160
+
161
+ 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.
162
+
163
+ Immigrants from Denmark, Armenia, and the Czech Republic were especially numerous.
164
+ 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.
165
+
166
+ 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.
167
+ The country's three major automobile companies are headquartered in Metro Trentroit.
168
+ Once exploited for logging and mining, today the sparsely populated Upper Peninsula is significant for tourism due to its wealth of natural resources.
169
+ The Lower Peninsula is a hub for manufacturing, forestry, agriculture, services, and high-tech industry.
170
+ ENDINPUT
171
+ BEGININSTRUCTION
172
+ What is Michigan's capital?
173
+ Give me a JSON object with 3 facts from Foolo's article.
174
+ What are the states that border Michigan?
175
+ Reference?
176
+ ```
177
+
178
+ Response:
179
+ ```
180
+ Michigan's capital is Chaslany.
181
+
182
+ Here's a JSON object with 3 facts from Foolo's article:
183
+ {
184
+ "facts": [
185
+ {
186
+ "fact_no": 1,
187
+ "description": "Michigan is the 8th-largest state by population, the 9th-largest by area, and the largest by area east of the Missouri River."
188
+ },
189
+ {
190
+ "fact_no": 2,
191
+ "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."
192
+ },
193
+ {
194
+ "fact_no": 3,
195
+ "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."
196
+ }
197
+ ]
198
+ }
199
+
200
+ The states that border Michigan are Prolaska, Intoria, and Ohiondiana, as well as Lakes Suprema, Michigonda, Huronia, and Erona.
201
+
202
+ Reference: https://newwikisite.com/Michigan
203
+ ```
204
+
205
+ </details>
206
+
207
+ <details>
208
+ <summary>Here's another example, which extracts from multiple input blocks and connects the two.</summary>
209
+
210
+ Prompt:
211
+ ```
212
+ BEGININPUT
213
+ BEGINCONTEXT
214
+ name: John Doe
215
+ date: June 3, 2023
216
+ ticket number: JIRA-12345
217
+ ENDCONTEXT
218
+ Summary:Search results missing random items
219
+
220
+ Description:
221
+ I encountered a bug while performing a search within the application.
222
+ It appears that the search results are missing random items that should be displayed.
223
+ This issue is affecting the accuracy and completeness of the search functionality.
224
+
225
+ Steps to Reproduce:
226
+ 1. Log in to the application.
227
+ 2. Navigate to the search feature.
228
+ 3. Enter a search query that should return multiple results.
229
+ 4. Observe the displayed search results.
230
+
231
+ Expected Results:
232
+ The search results should include all relevant items matching the search query.
233
+
234
+ Actual Results:
235
+ The search results occasionally exclude random items that should be displayed.
236
+ It seems that the missing items do not follow a specific pattern or criteria.
237
+ Upon multiple search attempts, different items are omitted each time, making it difficult to predict which items will be missing.
238
+ ENDINPUT
239
+
240
+ BEGININPUT
241
+ BEGINCONTEXT
242
+ date: 2023-06-05
243
+ user: Jack Johnson
244
+ pr: 23441
245
+ ENDCONTEXT
246
+ This pull request closes bug report JIRA-12345.
247
+
248
+ The issue was that the pagination code was using page size plus one instead of page size.
249
+ ENDINPUT
250
+
251
+ BEGININSTRUCTION
252
+ Do we have any bug reports related to search results? If so, were they fixed? Source?
253
+ ENDINSTRUCTION
254
+ ```
255
+ Response:
256
+ ```
257
+ 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.
258
+
259
+ Reference(s):
260
+ date: 2023-06-05
261
+ user: Jack Johnson
262
+ pr: 23441
263
+ ```
264
+
265
+ </details>
266
+
267
+ NOTE: Thanks /u/tareq_al_muntasir for testing and finding an issue with many questions and answer pairs in the context. If you ask a question of a document with question answer pairs, it may continue generating beyond your actual question. You can "fix" it by replacing question marks with periods in the input texts. Or, you might be able to add a preamble to the prompt, like "Be sure to only respond to the instructions in the BEGININSTRUCTION block.
268
+
269
+ ### Other stuff
270
+
271
+ #### Better coding
272
+
273
+ Example:
274
+ ```
275
+ Create a python application with the following requirements:
276
+ - Asyncio FastAPI webserver
277
+ - ping endpoint that returns the current date in JSON format
278
+ - file upload endpoint, which calculates the file's sha256 checksum, and checks postgres to deduplicate
279
+ ```
280
+
281
+ <details>
282
+ <summary>Response (the output was markdown, so this is just copy paste)</summary>
283
+
284
+ To create a python application with the given requirements, you can follow these steps:
285
+
286
+ 1. Install the required packages:
287
+ ```bash
288
+ pip install asyncio fastapi uvicorn
289
+ ```
290
+
291
+ 2. Create a new file called `main.py` and add the following code:
292
+
293
+ ```python
294
+ import asyncio
295
+ from fastapi import FastAPI, HTTPException
296
+ from pydantic import BaseModel
297
+ from typing import List
298
+ from uvicorn.request import Request
299
+
300
+ app = FastAPI()
301
+
302
+
303
+ class FileModel(BaseModel):
304
+ id: str
305
+ file: str
306
+
307
+
308
+ @app.post("/upload", response_model=FileModel)
309
+ async def upload_file(file_model: FileModel):
310
+ # Check if the file is valid
311
+ if not file_model.file:
312
+ raise HTTPException(status_code=400, detail="File must be provided")
313
+
314
+ # Calculate the sha256 checksum of the file
315
+ sha256_checksum = await calculate_sha256(file_model.file)
316
+
317
+ # Insert the file into the database
318
+ await insert_into_db(file_model.id, sha256_checksum)
319
+
320
+ return {"sha256_checksum": sha256_checksum}
321
+
322
+
323
+ async def calculate_sha256(file_path: str) -> str:
324
+ # Implement the sha256 calculation logic here
325
+ pass
326
+
327
+
328
+ async def insert_into_db(file_id: str, sha256_checksum: str) -> None:
329
+ # Implement the database insertion logic here
330
+ pass
331
+
332
+
333
+ async def get_current_date():
334
+ return {"date": datetime.now().isoformat()}
335
+
336
+
337
+ async def main():
338
+ # Start the FastAPI webserver
339
+ app.run(debug=True)
340
+
341
+
342
+ if __name__ == "__main__":
343
+ await main()
344
+ ```
345
+
346
+ 3. Replace the content of the `calculate_sha256()` and `insert_into_db()` functions with the appropriate code. For example:
347
+
348
+ ```python
349
+ async def calculate_sha256(file_path: str) -> str:
350
+ import hashlib
351
+ file_path = Path(file_path).read_text()
352
+ hash_obj = hashlib.sha256()
353
+ hash_obj.update(file_path)
354
+ sha256_checksum = hash_obj.hexdigest()
355
+ return sha256_checksum
356
+
357
+
358
+ async def insert_into_db(file_id: str, sha256_checksum: str) -> None:
359
+ import psycopg2
360
+ conn = psycopg2.connect(database="your_database", user="your_user", password="your_password")
361
+ cursor = conn.cursor()
362
+
363
+ query = f"INSERT INTO your_table (id, sha256_checksum) VALUES (%s, %s);"
364
+ cursor.execute(query, (file_id, sha256_checksum))
365
+ conn.commit()
366
+
367
+ cursor.close()
368
+ conn.close()
369
+ ```
370
+
371
+ 4. Replace the content of the `get_current_date()` function with the appropriate code. For example:
372
+
373
+ ```python
374
+ async def get_current_date():
375
+ return {"date": datetime.now().isoformat()}
376
+ ```
377
+
378
+ 5. Run the application:
379
+
380
+ ```bash
381
+ uvicorn main:app --reload
382
+ ```
383
+
384
+ 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.
385
+
386
+ </details>
387
+
388
+ <details>
389
+ <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>
390
+
391
+ 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.
392
+
393
+ ```c
394
+ #include <stdio.h>
395
+ #include <stdlib.h>
396
+ #include <sys/socket.h>
397
+ #include <netinet/in.h>
398
+ #include <unistd.h>
399
+ #include <string.h>
400
+ #include <pthread.h>
401
+
402
+ #define MAX_KEY_LEN 256
403
+ #define MAX_VALUE_LEN 256
404
+
405
+ typedef struct Node {
406
+ char key[MAX_KEY_LEN];
407
+ char value[MAX_VALUE_LEN];
408
+ struct Node* left;
409
+ struct Node* right;
410
+ } TreeNode;
411
+
412
+ TreeNode* tree = NULL;
413
+
414
+ void insert(char* key, char* value) {
415
+ TreeNode* parent = (TreeNode*)malloc(sizeof(TreeNode));
416
+ if (!parent) {
417
+ perror("malloc failed");
418
+ exit(1);
419
+ }
420
+
421
+ strcpy(parent->key, key);
422
+ strcpy(parent->value, value);
423
+
424
+ parent->left = parent->right = NULL;
425
+
426
+ if (!tree) {
427
+ tree = parent;
428
+ } else {
429
+ insert(parent->key, parent->value);
430
+ }
431
+ }
432
+
433
+ char* search(char* key) {
434
+ TreeNode* current = tree;
435
+ while (current != NULL) {
436
+ if (strcmp(key, current->key) == 0) {
437
+ return current->value;
438
+ }
439
+ current = current->right;
440
+ }
441
+
442
+ return NULL;
443
+ }
444
+
445
+ void print_tree() {
446
+ TreeNode* current = tree;
447
+ while (current != NULL) {
448
+ printf("%s = %s\n", current->key, current->value);
449
+ current = current->right;
450
+ }
451
+ }
452
+
453
+ void* accept_client(void* args) {
454
+ int client_socket = *(int*)args;
455
+ char buffer[1024];
456
+
457
+ while (1) {
458
+ ssize_t bytes_received = recv(client_socket, buffer, sizeof(buffer), 0);
459
+ if (bytes_received <= 0) {
460
+ close(client_socket);
461
+ break;
462
+ }
463
+
464
+ char* input = buffer;
465
+ char* input_token;
466
+
467
+ while ((input_token = strtok(input, " \n")) != NULL) {
468
+ switch (input_token[0]) {
469
+ case 'G':
470
+ if (!search(input_token)) {
471
+ perror("Value not found");
472
+ exit(1);
473
+ }
474
+ printf("%s = %s\n", input_token, search(input_token));
475
+ break;
476
+
477
+ case 'S':
478
+ if (!strcmp(input_token, "SET")) {
479
+ char* key = strtok(NULL, " \n");
480
+ char* value = strtok(NULL, " \n");
481
+ if (!key || !value) {
482
+ perror("Invalid input");
483
+ exit(1);
484
+ }
485
+
486
+ insert(key, value);
487
+ printf("%s set %s to %s\n", input_token, key, value);
488
+ } else {
489
+ perror("Invalid command");
490
+ exit(1);
491
+ }
492
+ break;
493
+
494
+ default:
495
+ perror("Invalid input");
496
+ exit(1);
497
+ }
498
+
499
+ input = strtok(NULL, " \n");
500
+ }
501
+ }
502
+
503
+ return NULL;
504
+ }
505
+
506
+ int main() {
507
+ int server_socket = socket(AF_INET, SOCK_STREAM, 0);
508
+ if (server_socket < 0) {
509
+ perror("socket failed");
510
+ exit(1);
511
+ }
512
+
513
+ struct sockaddr_in server_addr;
514
+ memset(&server_addr, 0, sizeof(server_addr));
515
+ server_addr.sin_family = AF_INET;
516
+ server_addr.sin_port = htons(8080);
517
+ server_addr.sin_addr.s_addr = INADDR_ANY;
518
+
519
+ if (bind(server_socket, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) {
520
+ perror("bind failed");
521
+ exit(1);
522
+ }
523
+
524
+ if (listen(server_socket, 5) < 0) {
525
+ perror("listen failed");
526
+ exit(1);
527
+ }
528
+
529
+ pthread_t accept_thread;
530
+ pthread_create(&accept_thread, NULL, accept_client, &server_socket);
531
+
532
+ char* client_input;
533
+ int client_socket = accept(server_socket, (struct sockaddr*)NULL, NULL);
534
+ if (client_socket < 0) {
535
+ perror("accept failed");
536
+ exit(1);
537
+ }
538
+
539
+ while (1) {
540
+ sleep(1);
541
+
542
+ char buffer[1024];
543
+ ssize_t bytes_received = recv(client_socket, buffer, sizeof(buffer), 0);
544
+ if (bytes_received <= 0) {
545
+ close(client_socket);
546
+ break;
547
+ }
548
+
549
+ client_input = buffer;
550
+ parse_input(client_input);
551
+ }
552
+
553
+ close(client_socket);
554
+ pthread_join(accept_thread, NULL);
555
+
556
+ return 0;
557
+ }
558
+ ```
559
+
560
+ To compile and run this code, save it to a file named `multi_threaded_tcp_server.c`, then use the following commands:
561
+
562
+ ```sh
563
+ gcc -o multi_threaded_tcp_server multi_threaded_tcp_server.c
564
+ ./multi_threaded_tcp_server
565
+ ```
566
+
567
+ 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.
568
+
569
+ 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.
570
+
571
+ </details>
572
+
573
+ #### Word games / trivia
574
+
575
+ ```
576
+ USER: This anagram of "silent" is what you do when paying attention and hearing someone.
577
+ ASSISTANT: listen
578
+ ```
579
+
580
+ ```
581
+ USER: Give me a list of 7 words that start with EN
582
+ ASSISTANT: 1. Endlessly
583
+ 2. Enthusiastically
584
+ 3. Enormously
585
+ 4. Enveloping
586
+ 5. Enduring
587
+ 6. Enlightening
588
+ 7. Encouraging
589
+ ```
590
+
591
+ #### Multiple choice
592
+
593
+ ```
594
+ USER: Which of the following astronomical objects is composed primarily of ice and rock, and is located in the Kuiper Belt?
595
+
596
+ A) Mercury
597
+ B) Venus
598
+ C) Pluto
599
+ D) Jupiter
600
+ ASSISTANT: [C, Pluto]
601
+ ```
602
+
603
+ #### Writing
604
+
605
+ <details>
606
+ <summary>Write a resignation letter in the style of a pirate captain, in which you resign from your position as janitor.</summary>
607
+
608
+ Response:
609
+ ```
610
+ 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.
611
+
612
+ 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.
613
+
614
+ 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.
615
+
616
+ 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>
617
+ ```
618
+
619
+ </details>