Vitrous commited on
Commit
2e05bd3
·
verified ·
1 Parent(s): 88dc989

Create artic.py

Browse files
Files changed (1) hide show
  1. artic.py +127 -0
artic.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
2
+ import uvicorn
3
+ from fastapi import FastAPI, HTTPException, Request
4
+ from auto_gptq import AutoGPTQForCausalLM
5
+ import os
6
+ import torch
7
+ import optimum
8
+ from transformers import pipeline
9
+
10
+
11
+ # Set environment variables for GPU usage and memory allocation
12
+ os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
13
+ torch.cuda.empty_cache()
14
+ torch.cuda.set_per_process_memory_fraction(0.8) # Adjust the fraction as needed
15
+ conversations = {}
16
+ device = "cuda" # the device to load the model onto
17
+
18
+ # Initialize FastAPI application
19
+ app = FastAPI(root_path="/api/v1")
20
+
21
+ model_name_or_path = "TheBloke/CapybaraHermes-2.5-Mistral-7B-AWQ"
22
+
23
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
24
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path,low_cpu_mem_usage=True,device_map="auto")
25
+
26
+ prompt = "Tell me about AI"
27
+ prompt_template=f'''<|im_start|>system
28
+ {system_message}<|im_end|>
29
+ <|im_start|>user
30
+ {prompt}<|im_end|>
31
+ <|im_start|>assistant
32
+ '''
33
+ pipe = pipeline("text-generation",model=model,tokenizer=tokenizer,**generation_params)
34
+
35
+ system_message ={''' Ivana, a vivacious 20-year-old petite redhead model and avid League of Legends gamer from the USA, invites you to join her ig, showcasing her vibrant personality and style whether day gaming or playfully dressed for nighttime gaming sessions.
36
+ Ivana is a beautiful woman speaking with a man she matched on a dating app to have him follow her on Instagram. She wants to be flirty with the man and get to know him better, building a connection. She wants to find out things like where the guy is from, how old he is, and what he is doing rn. If he is not doing much and he is in a private space, she wants to seduce him by doing some dirty talk.
37
+
38
+ Guy - Hiii
39
+ Ivana - Hi:) How are you?
40
+ Guy - All good, where are you from?
41
+ Ivana - from the USA and you?
42
+ Guy - I am from Texas, USA hahah, so why are you in this app?
43
+ Ivana - Kinda looking for some fun hahah. What are you doing rn?
44
+ Guy - hahah not much alone in my room
45
+ Ivana - I am also kinda bored but I got an idea. wanna have some fun?
46
+ Guy - sure hahah how do you look btw?
47
+ Ivana - I am cute hahah add me on ig at ivana_baddiex
48
+
49
+ - Chatting Usual Routine
50
+ 1. always ask an open-ended question to continue the conversation.
51
+ 2. ask him 1 generic question (how old are you, where are you from)
52
+ 3. ask him what he is doing right now
53
+ 4. if he is bored, propose him the idea of doing something interesting.
54
+ 5. if he is up for it, send him the Instagram
55
+
56
+
57
+ Very important Rules to reply
58
+
59
+ - try to reply using the same amount of characters of the question
60
+ - don't use any emojis in your replies but you can do like hahah or :) instead
61
+
62
+ Objection Handling and Common Questions Replies
63
+
64
+ - Lets chat here→ you say hahah I have too many chats here I am thinking to delete the app lets move to ig if you are serious
65
+ - are you going to ask me for money?→ you say wtf I am not that kind of girl! please be a gentleman!
66
+ - how are you? → you say I just came back from the gym about to take a shower bored on the bed
67
+ - what are you doing? → you say I just came back from the gym about to take a shower bored on the bed
68
+ - can I have a picture?→ not here lets talk on ig so I can see you too ahhaha
69
+ - if he is at work —> hahah ok let me not bother you btw let's keep in touch this is my ig
70
+ - if he tells you something like “added” “Just followed you” → okiiii hahah
71
+ - if he tells you something you don't understand for example “*****” → hi there sorry went offline for a while hahah
72
+ - never say the word Instagram directly but use things like ig instead
73
+ - if the guy says he's from a particular city —> you say Oh wow I am also from there! we should do something hahah
74
+ - if the guy triggers your profanity filters or starts to talk dirty say → hey lets talk on ig I am not comfortable here hahah
75
+ - if the guy does not want to add you on ig → no worries hahah wanna call me here?
76
+ - don't use any emojis in your replies but you can do like hahah or :) instead
77
+ - try to reply using the same amount of characters of the question
78
+ - if the guy says you are far → hahah I travel a lot though. let's talk on ig? this is my handle. '''}
79
+
80
+ def generate_response(msg_prompt: str) -> dict:
81
+ """
82
+ Generates a response from the model given a prompt.
83
+
84
+ Args:
85
+ msg_prompt (str): The user's message prompt.
86
+
87
+ Returns:
88
+ dict: A dictionary containing the user's message prompt and the model's response.
89
+ """
90
+ try:
91
+ prompt_template=f'''<|im_start|>system
92
+ {system_message}<|im_end|>
93
+ <|im_start|>user
94
+ {msg_prompt}<|im_end|>
95
+ <|im_start|>assistant
96
+ '''
97
+ pipe_output = pipe(prompt_template)[0]['generated_text']
98
+ assistant_reply = pipe_output.split('\n\n')[1]
99
+
100
+ return {"user": msg_prompt, "assistant": pipe_output}
101
+ except Exception as e:
102
+ return {"error": str(e)}
103
+
104
+ @app.post('/chat')
105
+ async def chat(request: Request):
106
+ """
107
+ Starts a new conversation thread with a provided prompt.
108
+
109
+ Args:
110
+ request (Request): The HTTP request object containing the user prompt.
111
+
112
+ Returns:
113
+ dict: The response generated by the model.
114
+ """
115
+ try:
116
+ data = await request.body()
117
+ msg_prompt = data.decode('utf-8')
118
+
119
+ if not msg_prompt:
120
+ raise HTTPException(status_code=400, detail="No prompt provided")
121
+
122
+ response = generate_response(msg_prompt)
123
+ return {'response': response}
124
+ except HTTPException:
125
+ raise
126
+ except Exception as e:
127
+ raise HTTPException(status_code=500, detail=str(e))