forked from irmen/Tale
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from neph1/give_and_json
LLM decision making (experimental)
- Loading branch information
Showing
34 changed files
with
1,168 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import tale | ||
from tale.base import Location, Item, Living | ||
from tale.driver import Driver | ||
from tale.player import Player | ||
from tale.story import StoryBase, StoryConfig | ||
import tale.parse_utils as parse_utils | ||
|
||
class JsonStory(StoryBase): | ||
|
||
def __init__(self, path: str, config: StoryConfig): | ||
self.config = config | ||
self.path = path | ||
locs = {} | ||
for zone in self.config.zones: | ||
locs, exits = parse_utils.load_locations(parse_utils.load_json(self.path +'zones/'+zone + '.json')) | ||
self._locations = locs | ||
self.zones = locs | ||
self._npcs = parse_utils.load_npcs(parse_utils.load_json(self.path +'npcs/'+self.config.npcs + '.json'), self._locations) | ||
self._items = parse_utils.load_items(parse_utils.load_json(self.path + self.config.items + '.json'), self._locations) | ||
|
||
def init(self, driver) -> None: | ||
pass | ||
|
||
|
||
def welcome(self, player: Player) -> str: | ||
player.tell("<bright>Welcome to `%s'.</>" % self.config.name, end=True) | ||
player.tell("\n") | ||
player.tell("\n") | ||
return "" | ||
|
||
def welcome_savegame(self, player: Player) -> str: | ||
return "" # not supported in demo | ||
|
||
def goodbye(self, player: Player) -> None: | ||
player.tell("Thanks for trying out Tale!") | ||
|
||
def get_location(self, zone: str, name: str) -> Location: | ||
return self._locations[zone][name] | ||
|
||
def get_npc(self, npc: str) -> Living: | ||
return self._npcs[npc] | ||
|
||
def get_item(self, item: str) -> Item: | ||
return self._items[item] | ||
|
||
@property | ||
def locations(self) -> dict: | ||
return self._locations | ||
|
||
@property | ||
def npcs(self) -> dict: | ||
return self._npcs | ||
|
||
@property | ||
def items(self) -> dict: | ||
return self._items | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
URL: "http://localhost:5001" | ||
ENDPOINT: "/api/v1/generate" | ||
DEFAULT_BODY: '{"stop_sequence": "\n\n", "max_length":300, "max_context_length":4096, "temperature":1.0, "top_k":120, "top_a":0.0, "top_p":0.85, "typical_p":1.0, "tfs":1.0, "rep_pen":1.2, "rep_pen_range":256, "mirostat":2, "mirostat_tau":5.0, "mirostat_eta":0.1, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}' | ||
MEMORY_SIZE: 1024 | ||
STREAM: False | ||
STREAM_ENDPOINT: "/api/extra/generate/stream" | ||
DATA_ENDPOINT: "/api/extra/generate/check" | ||
WORD_LIMIT: 500 | ||
DEFAULT_BODY: '{"stop_sequence": "", "max_length":500, "max_context_length":4096, "temperature":1.0, "top_k":120, "top_a":0.0, "top_p":0.85, "typical_p":1.0, "tfs":1.0, "rep_pen":1.2, "rep_pen_range":256, "mirostat":2, "mirostat_tau":5.0, "mirostat_eta":0.1, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}' | ||
ANALYSIS_BODY: '{"banned_tokens":"\n\n", "stop_sequence": "", "max_length":500, "max_context_length":4096, "temperature":0.15, "top_k":120, "top_a":0.0, "top_p":0.85, "typical_p":1.0, "tfs":1.0, "rep_pen":1.2, "rep_pen_range":256, "mirostat":2, "mirostat_tau":5.0, "mirostat_eta":0.1, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}' | ||
MEMORY_SIZE: 512 | ||
PRE_PROMPT: 'Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n' | ||
BASE_PROMPT: '### Instruction: Rewrite the following text in your own words using vivid language. Text:\n\n {input_text} \n\nEnd of text.\n\n### Response:\n\n' | ||
DIALOGUE_PROMPT: 'The following is a conversation between {character1} and {character2}. {character2_description}. Chat history: {previous_conversation}\n\n### Instruction: Write a single response as {character2}, using {character2} description.\n\n### Response:\n' | ||
ITEM_PROMPT: '### Instruction: Perform an analysis of the following text. Consider whether an item has been given, taken, dropped or put somewhere. Text:\n\n{text}\n\nEnd of text.\n\n Write your response in json format.\n\n Example {\n\n"thoughts":your thoughts on whether an item has been given, taken, dropped or put, and to whom/where.\n\n"result": {"item":"what item?", "from":"?", "to":"?"}\n\n}\n\nInsert the results from your analysis in "item", "from" and "to", or make them empty if no item was given, taken, dropped or put somewhere. Make sure the answer is valid json\n\n### Response:\n\n' | ||
COMBAT_PROMPT: '### Instruction: Rewrite the following combat result into a vivid description. Write one to two paragraphs, ending in either death, or a stalemate. Combat Result: {result}\n\n### Response:\n\n' | ||
BASE_PROMPT: "History: [{history}]. ### Instruction: Rewrite the following text in your own words using vivid language. 'History' can be used to create a context for what you write. Text:\n\n [{input_text}] \n\nEnd of text.\n\n### Response:\n" | ||
DIALOGUE_PROMPT: 'The following is a conversation between {character1} and {character2}. {character2_description}. Chat history: {previous_conversation}\n\n {character2}s sentiment towards {character1}: {sentiment}. ### Instruction: Write a single response as {character2}, using {character2} description.\n\n### Response:\n' | ||
ITEM_PROMPT: '### Instruction: Items:[{items}];Characters:[{character1},{character2}] Text:[{text}] \n\nIn the supplied text, was an item explicitly given, taken, dropped or put somewhere? Insert your thoughts about it in [my thoughts], and the results in "item", "from" and "to". Insert {character1}s sentiment towards {character2} in a single word in [sentiment assessment]. Write your response in JSON format. Example: {{ "thoughts":"[my thoughts]", "result": {{ "item":"", "from":"", "to":""}}, {{"sentiment":"[sentiment assessment]"}} }} End of example. \n\n Make sure the response is valid JSON\n\n### Response:\n' | ||
|
||
COMBAT_PROMPT: '### Instruction: Rewrite the following combat result into a vivid description. Write one to two paragraphs, ending in either death, or a stalemate. Combat Result: {result}\n\n### Response:\n' | ||
|
||
|
Oops, something went wrong.