rAIfle commited on
Commit
0a2f5ee
1 Parent(s): 869539f

Upload 12 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ configs/silly_tavern/cards/Seraphina.png filter=lfs diff=lfs merge=lfs -text
configs/lmstudio/preset.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "OpusV1StoryWriting",
3
+ "inference_params": {
4
+ "input_prefix": "<|im_end|>\n<|im_start|>user\n",
5
+ "input_suffix": "<|im_end|>\n<|im_start|>text\n",
6
+ "antiprompt": ["<|im_start|>", "<|im_end|>"],
7
+ "pre_prompt_prefix": "<|im_start|>system\n",
8
+ "pre_prompt_suffix": "",
9
+ "pre_prompt": "You are an intelligent, skilled, versatile writer.\n\nYour task is to write a story based on the information below.\n\n## Overall plot description:\n\n"
10
+ }
11
+ }
configs/silly_tavern/cards/LaraLightland.png ADDED
configs/silly_tavern/cards/Seraphina.png ADDED

Git LFS Details

  • SHA256: 17520ffc2eec5a52a74a11769c6cedad48e4f4949dda89ad2eff95afda20c85d
  • Pointer size: 132 Bytes
  • Size of remote file: 1.39 MB
configs/silly_tavern/settings_screenshot.webp ADDED
configs/silly_tavern/v1/context_settings.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "story_string": "<|im_start|>system\nYou are an intelligent, skilled, versatile writer.\n\nYour task is to write a story based on the information below.\n\n\n## Overall plot description:\n\n{{scenario}}\n\n{{description}}\n\n\n## Characters:\n\n### {{char}}\n{{personality}}\n{{persona}}<|im_end|>",
3
+ "example_separator": "",
4
+ "chat_start": "",
5
+ "use_stop_strings": false,
6
+ "always_force_name2": false,
7
+ "trim_sentences": false,
8
+ "include_newline": false,
9
+ "single_line": false,
10
+ "name": "ChatMLOpusV1_ST2"
11
+ }
configs/silly_tavern/v1/instruct_mode_settings.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "system_prompt": "",
3
+ "input_sequence": "<|im_start|>text names= {{user}}\n",
4
+ "output_sequence": "<|im_end|>\n<|im_start|>text names= {{char}}\n",
5
+ "first_output_sequence": "",
6
+ "last_output_sequence": "",
7
+ "system_sequence_prefix": "",
8
+ "system_sequence_suffix": "",
9
+ "stop_sequence": "",
10
+ "separator_sequence": "<|im_end|>\n",
11
+ "wrap": false,
12
+ "macro": true,
13
+ "names": false,
14
+ "names_force_groups": false,
15
+ "activation_regex": "",
16
+ "name": "ChatMLOpusV1_ST1"
17
+ }
configs/silly_tavern/v2/context_settings.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "story_string": "<|im_start|>system\n{{#if system}}{{system}}\n\n\n{{/if}}## Overall plot description:\n\n{{#if wiBefore}}{{wiBefore}}\n\n{{/if}}{{#if scenario}}{{scenario}}\n\n\n{{/if}}## Characters:\n\n### {{char}}\n{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{personality}}\n\n{{/if}}### {{user}}\n{{#if persona}}{{persona}}\n\n{{/if}}{{#if wiAfter}}{{wiAfter}}\n\n{{/if}}{{#if mesExamples}}## {{char}}'s example message:\n\n{{mesExamples}}{{/if}}",
3
+ "example_separator": "",
4
+ "chat_start": "",
5
+ "use_stop_strings": false,
6
+ "always_force_name2": false,
7
+ "trim_sentences": true,
8
+ "include_newline": false,
9
+ "single_line": false,
10
+ "name": "ChatMLOpusV1_ST2"
11
+ }
configs/silly_tavern/v2/instruct_mode_settings.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "system_prompt": "You are an intelligent, skilled, versatile writer.\n\nYour task is to write a role-play based on the information below.\n\n\n## Style description:\n\nThis role-play is written as a third-person introspective narrative in past tense. Scenes are described vividly, with great detail.",
3
+ "input_sequence": "<|im_end|>\n<|im_start|>text names= {{user}}\n",
4
+ "output_sequence": "<|im_end|>\n<|im_start|>text names= {{char}}\n",
5
+ "first_output_sequence": "",
6
+ "last_output_sequence": "<|im_end|>\n<|im_start|>user\nLength: 400 words\n{{char}} replies to {{user}} in detailed and elaborate way.<|im_end|>\n<|im_start|>text names= {{char}}\n",
7
+ "system_sequence_prefix": "",
8
+ "system_sequence_suffix": "",
9
+ "stop_sequence": "",
10
+ "separator_sequence": "",
11
+ "wrap": false,
12
+ "macro": true,
13
+ "names": false,
14
+ "names_force_groups": false,
15
+ "activation_regex": "",
16
+ "name": "ChatMLOpusV1_ST2"
17
+ }
example/interactive.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # python interactive.py
2
+
3
+ # %%
4
+
5
+ import fileinput
6
+
7
+
8
+ from vllm import LLM, SamplingParams
9
+
10
+ from prompt.format import (
11
+ format_opus_v1_prompt,
12
+ OpusV1Character,
13
+ OpusV1Prompt,
14
+ OpusV1StorySystemPrompt,
15
+ OpusV1Turn,
16
+ )
17
+
18
+
19
+ # %%
20
+
21
+
22
+ def main():
23
+ sampling_params = SamplingParams(
24
+ # I usually stay between 0.0 and 1.0, especially for the Yi models I found lower tends to be better.
25
+ # For assistant tasks, I usually use 0.0.
26
+ temperature=0.8,
27
+ min_p=0.05,
28
+ presence_penalty=0.1,
29
+ frequency_penalty=0.1,
30
+ repetition_penalty=1.1,
31
+ max_tokens=200,
32
+ ignore_eos=True,
33
+ skip_special_tokens=False,
34
+ spaces_between_special_tokens=False,
35
+ stop=["<|im_end|>"],
36
+ include_stop_str_in_output=False,
37
+ )
38
+
39
+ # Set max_model_len to fit in memory.
40
+ model = LLM(
41
+ "dreamgen/opus-v1.2-7b",
42
+ max_model_len=2000,
43
+ enforce_eager=True,
44
+ swap_space=0,
45
+ gpu_memory_utilization=0.85,
46
+ )
47
+
48
+ plot_description = """
49
+ This is a fanfiction from the Harry Potter universe. In this alternate reality, Harry Potter is evil and secretly siding with Slytherin.
50
+ Up until now, Harry was pretending to be friends with Hermione and Ron, that changes when he invites Hermione to his chambers where he tricks her to drink Amorentia, the most powerful love potion.
51
+ """
52
+
53
+ char1 = OpusV1Character(
54
+ name="Harry Potter",
55
+ description="""Harry Potter in this fanfiction is secretly a member of Slytherin and is using his powers for evil rather than for good. Up until now, he was pretending to be friends with Hermione and Ron.""",
56
+ )
57
+ char2 = OpusV1Character(
58
+ name="Hermione Granger",
59
+ description="""Hermione appears just like in the original books.""",
60
+ )
61
+
62
+ story_prompt = OpusV1StorySystemPrompt(
63
+ plot_description=plot_description,
64
+ style_description="",
65
+ characters=[char1, char2],
66
+ )
67
+
68
+ turns = [
69
+ OpusV1Turn(
70
+ role="user",
71
+ content="""Harry invites Hermione into his chamber and offers her water, which Hermione happily accepts and drinks.""".strip(),
72
+ ),
73
+ OpusV1Turn(
74
+ role="text",
75
+ names=[char1.name],
76
+ content="""“Come in,” said Harry, waving at the doorway behind Hermione’s back.""".strip(),
77
+ ),
78
+ ]
79
+
80
+ def run():
81
+ turns.append(OpusV1Turn(role="text", content="", names=[char2.name], open=True))
82
+
83
+ prompt = OpusV1Prompt(story=story_prompt, turns=turns)
84
+
85
+ output = model.generate(
86
+ format_opus_v1_prompt(prompt), sampling_params, use_tqdm=False
87
+ )
88
+
89
+ response = OpusV1Turn(
90
+ role="text", content=output[0].outputs[0].text.strip(), names=[char2.name]
91
+ )
92
+ turns.append(response)
93
+ print(pretty_turn(response), flush=True)
94
+ print(f"[{char1.name}]: ", end="", flush=True)
95
+
96
+ print("## Plot description:\n")
97
+ print(plot_description.strip() + "\n\n")
98
+
99
+ for turn in turns:
100
+ print(pretty_turn(turn))
101
+
102
+ run()
103
+
104
+ for line in fileinput.input():
105
+ line = line.strip()
106
+ if line.startswith("/ins"):
107
+ content = line[4:].strip()
108
+ role = "user"
109
+ names = []
110
+ else:
111
+ content = line
112
+ role = "text"
113
+ names = [char1.name]
114
+
115
+ turns.append(OpusV1Turn(role=role, content=content, names=names))
116
+ run()
117
+
118
+
119
+ def pretty_turn(turn):
120
+ if turn.role == "user":
121
+ return f"/ins {turn.content.strip()}"
122
+ else:
123
+ if len(turn.names) > 0:
124
+ return f"[{turn.names[0]}]: {turn.content.strip()}"
125
+ else:
126
+ return turn.content.strip()
127
+
128
+
129
+ main()
example/prompt/__init__.py ADDED
File without changes
example/prompt/format.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %%
2
+ from typing import Optional, List
3
+ from dataclasses import field, dataclass
4
+
5
+
6
+ @dataclass
7
+ class OpusV1Turn:
8
+ role: str
9
+ content: str
10
+ names: List[str] = field(default_factory=list)
11
+ # If set to true, will not append <|im_end|>, so the model will continue the turn.
12
+ # In RP you can for example use the following to force a specific character response:
13
+ # role="text"
14
+ # names=["Jack"]
15
+ # open="true"
16
+ open: bool = False
17
+
18
+
19
+ @dataclass
20
+ class OpusV1Character:
21
+ name: str
22
+ description: str
23
+
24
+
25
+ @dataclass
26
+ class OpusV1StorySystemPrompt:
27
+ format: str = "prose"
28
+ plot_description: str = ""
29
+ style_description: str = ""
30
+ characters: List[OpusV1Character] = field(default_factory=list)
31
+
32
+
33
+ @dataclass
34
+ class OpusV1Prompt:
35
+ story: Optional[OpusV1StorySystemPrompt] = None
36
+ turns: List[OpusV1Turn] = field(default_factory=list)
37
+
38
+
39
+ def format_opus_v1_prompt(prompt) -> str:
40
+ turns = prompt.turns
41
+ if prompt.story is not None:
42
+ system = format_opus_v1_system_prompt(prompt.story)
43
+ turns = [OpusV1Turn(role="system", content=system)] + turns
44
+
45
+ parts = []
46
+ for i, turn in enumerate(turns):
47
+ assert turn.role in ["user", "text", "system", "assistant"]
48
+ assert turn.role != "system" or i == 0
49
+
50
+ is_last = i == len(turns) - 1
51
+ open = is_last and turn.open
52
+ parts.append(format_turn(turn.role, turn.content, turn.names, open=open))
53
+ return "".join(parts)
54
+
55
+
56
+ def format_turn(
57
+ role: str, content: str, names: List[str] = [], open: bool = False
58
+ ) -> str:
59
+ im_start = "<|im_start|>"
60
+ im_end = "<|im_end|>"
61
+
62
+ body = im_start + role
63
+ if len(names) > 0:
64
+ body += f" names= {'; '.join(names)}"
65
+
66
+ body += "\n"
67
+ if open:
68
+ return body + content.lstrip()
69
+ else:
70
+ return body + content.strip() + im_end + "\n"
71
+
72
+
73
+ def format_opus_v1_system_prompt(prompt) -> str:
74
+ format_text = "story" if prompt.format == "prose" else "role-play"
75
+ system = f"""
76
+ You are an intelligent, skilled, versatile writer.
77
+
78
+ Your task is to write a {format_text} based on the information below.
79
+
80
+ Write the {format_text} as if it's a book.
81
+ """.strip()
82
+
83
+ if len(prompt.plot_description) > 0:
84
+ system += "\n\n\n## Plot description:\n\n"
85
+ system += prompt.plot_description.strip()
86
+ if len(prompt.style_description) > 0:
87
+ system += "\n\n\n## Style description:\n\n"
88
+ system += prompt.style_description.strip()
89
+ if len(prompt.characters) > 0:
90
+ system += "\n\n\n## Characters:\n\n"
91
+ for character in prompt.characters:
92
+ system += f"### {character.name}\n\n"
93
+ system += character.description.strip()
94
+ system += "\n\n"
95
+
96
+ return system.strip()
example/simple.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # python simple.py
2
+
3
+ # %%
4
+
5
+ from vllm import LLM, SamplingParams
6
+
7
+ from prompt.format import (
8
+ format_opus_v1_prompt,
9
+ OpusV1Character,
10
+ OpusV1Prompt,
11
+ OpusV1StorySystemPrompt,
12
+ OpusV1Turn,
13
+ )
14
+
15
+
16
+ # %%
17
+
18
+
19
+ def build_story_prompt() -> OpusV1Prompt:
20
+ plot_description = """
21
+ This is a fanfiction from the Harry Potter universe. In this alternate reality, Harry Potter is evil and secretly siding with Slytherin.
22
+ Up until now, Harry was pretending to be friends with Hermione and Ron, that changes when he invites Hermione to his chambers where he tricks her to drink Amorentia, the most powerful love potion.
23
+ """
24
+
25
+ harry_description = """
26
+ Harry Potter in this fanfiction is secretly a member of Slytherin and is using his powers for evil rather than for good. Up until now, he was pretending to be friends with Hermione and Ron.
27
+ """
28
+
29
+ hermione_description = """
30
+ Hermione appears just like in the original books.
31
+ """
32
+
33
+ story_prompt = OpusV1StorySystemPrompt(
34
+ plot_description=plot_description,
35
+ style_description="",
36
+ characters=[
37
+ OpusV1Character(name="Harry Potter", description=harry_description),
38
+ OpusV1Character(name="Hermione Granger", description=hermione_description),
39
+ ],
40
+ )
41
+
42
+ return OpusV1Prompt(
43
+ story=story_prompt,
44
+ turns=[
45
+ OpusV1Turn(
46
+ role="user",
47
+ content="""
48
+ The story starts with Harry welcoming Hermione into his chambers, who he invited there earlier that day. He offers her water to drink, but it contains a love potion.
49
+ """.strip(),
50
+ ),
51
+ OpusV1Turn(
52
+ role="text",
53
+ content="""
54
+ “Come in,” said Harry, waving at the doorway behind Hermione’s back.
55
+
56
+ “Hello?” she said, stepping inside, “what did you want me to come up here for?”
57
+
58
+ “Well, I thought we could get away from all the noise down there, have a chat about what we plan to do for Christmas…” Harry said, fumbling for words. He had never really been any good with girls. “But anyway, please, take a seat and let me get us some water!” he said, darting over to the sideboard.
59
+
60
+ He returned quickly with two glasses of water. Hermione took hers and thanked him, taking in a big gulp. As soon as she swallowed, Harry saw her eyes widen as her heart began beating wildly in her chest.
61
+
62
+ It worked! Harry thought, grinning to himself. Amorentia truly was the world’s best love potion, its effects lasting twice as long and being five times stronger.
63
+ """.strip(),
64
+ open=True,
65
+ ),
66
+ ],
67
+ )
68
+
69
+
70
+ def build_assistant_prompt() -> OpusV1Prompt:
71
+ return OpusV1Prompt(
72
+ turns=[
73
+ OpusV1Turn(
74
+ role="system",
75
+ content="You are an intelligent, knowledgeable, helpful, general-purpose assistant.",
76
+ ),
77
+ OpusV1Turn(
78
+ role="user",
79
+ content="Give me a sentence where every word begins with 'S'",
80
+ ),
81
+ ]
82
+ )
83
+
84
+
85
+ # %%
86
+
87
+
88
+ def main():
89
+ sampling_params = SamplingParams(
90
+ # I usually stay between 0.0 and 1.0, especially for the Yi models I found lower tends to be better.
91
+ # For assistant tasks, I usually use 0.0.
92
+ temperature=0.0,
93
+ min_p=0.05,
94
+ presence_penalty=0.1,
95
+ frequency_penalty=0.1,
96
+ repetition_penalty=1.1,
97
+ max_tokens=200,
98
+ ignore_eos=True,
99
+ skip_special_tokens=False,
100
+ spaces_between_special_tokens=False,
101
+ )
102
+
103
+ # Set max_model_len to fit in memory.
104
+ model = LLM(
105
+ "dreamgen/opus-v1.2-7b",
106
+ max_model_len=2000,
107
+ enforce_eager=True,
108
+ swap_space=0,
109
+ gpu_memory_utilization=0.85,
110
+ )
111
+
112
+ story_prompt = build_story_prompt()
113
+ print(format_opus_v1_prompt(story_prompt))
114
+
115
+ output = model.generate(format_opus_v1_prompt(story_prompt), sampling_params)
116
+ print(output[0].outputs[0].text)
117
+
118
+ # Expected:
119
+ """
120
+ It would make her fall deeply in love with him, and then he could use her to get what he wanted.
121
+
122
+ “Harry, what’s going on? You look so happy!” Hermione asked, smiling at him.
123
+
124
+ “Oh, well, I guess I am,” Harry replied, trying not to laugh. “I mean, I’ve always known that you were the one for me.”
125
+
126
+ “Really?” Hermione asked, blushing slightly. “I didn’t know that.”
127
+
128
+ “Yeah, I’ve always had feelings for you,” Harry said, leaning forward and placing his hand on top of hers. “And now that I’ve got you alone, I can finally tell you how much I care about you.”
129
+ """
130
+
131
+
132
+ main()