premalt commited on
Commit
24a59b0
·
1 Parent(s): f9084ef

add tests and migrate to gpt2 for performance

Browse files
Files changed (2) hide show
  1. main.py +1 -1
  2. tests.ts +50 -0
main.py CHANGED
@@ -8,7 +8,7 @@ from typing import List
8
 
9
 
10
  app = FastAPI()
11
- client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
12
 
13
  SYSTEM_PROMPT = "You are a very powerful AI to generate interesting stories for short-form content consumption. Make sure to hook the readers attention in the first few seconds. Make sure to be engaging and creative in your responses."
14
 
 
8
 
9
 
10
  app = FastAPI()
11
+ client = InferenceClient("openai-community/gpt2")
12
 
13
  SYSTEM_PROMPT = "You are a very powerful AI to generate interesting stories for short-form content consumption. Make sure to hook the readers attention in the first few seconds. Make sure to be engaging and creative in your responses."
14
 
tests.ts ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function getRandomPrompt(): Promise<string> {
2
+ try {
3
+ const response = await fetch('https://random-word-api.vercel.app/api?words=5')
4
+ const words = await response.json()
5
+
6
+ return `Write a story about ${words.join(' ')}`
7
+ } catch (error) {
8
+ console.error('Error fetching random prompt:', error)
9
+ throw new Error('Failed to fetch random prompt')
10
+ }
11
+ }
12
+
13
+ async function makeRequests(url: string, numRequests: number) {
14
+ const prompts = await Promise.all(
15
+ Array.from({ length: numRequests }, () => getRandomPrompt())
16
+ )
17
+
18
+ console.log('Received prompts')
19
+ const startTime = Date.now()
20
+ console.log('Start time:', startTime)
21
+
22
+ const requests = prompts.map(async (randomPrompt) => {
23
+ const fullUrl = `${url}?prompt=${encodeURIComponent(randomPrompt)}&history=[]&system_prompt=You%20are%20a%20very%20powerful%20AI%20assistant.&temperature=0.7`
24
+ const response = await fetch(fullUrl)
25
+ return response.json()
26
+ })
27
+
28
+
29
+ let results: any[] = []
30
+
31
+ try {
32
+ results = await Promise.all(requests)
33
+ console.log('Received all responses.')
34
+ } catch (error) {
35
+ console.error('Error in one or more requests:', error)
36
+ }
37
+
38
+ const endTime = Date.now()
39
+ console.log('End time:', endTime)
40
+
41
+ const timeTaken = (endTime - startTime) / 1000
42
+ console.log(`Total time taken for ${numRequests} requests: ${timeTaken.toFixed(2)} seconds`)
43
+
44
+ // results.forEach((_, i) => console.log(results[i]))
45
+ }
46
+
47
+ const url = 'https://pr0methium-gen.hf.space/generate/'
48
+ makeRequests(url, 1000).catch((error) => {
49
+ console.error('Program stopped due to error:', error.message)
50
+ })