Skip to content

Commit

Permalink
fix: Uniformize persona role property
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Jul 4, 2024
1 parent f054856 commit 905a4a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@libertai/libertai-js",
"version": "0.0.6",
"version": "0.0.7",
"description": "In-browser SDK for interacting with LibertAI Decentralized AI Network",
"keywords": [],
"type": "module",
Expand Down
16 changes: 8 additions & 8 deletions src/inference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

import { Persona, Model, Message } from './types.js';
import { Message, Model, Persona } from './types.js';
import { calculateTokenLength } from './utils.js';

// Simple wrapper class around basic AI inference
Expand Down Expand Up @@ -69,9 +69,9 @@ export class LlamaCppApiEngine {
}

let fullResults = compoundedResult + lastResult;
for (let i = 0; i < stop_sequences.length; i++) {
fullResults = fullResults.split(`\n${stop_sequences[i]}`).join('|||||');
fullResults = fullResults.split(`${stop_sequences[i]}`).join('|||||');
for (const element of stop_sequences) {
fullResults = fullResults.split(`\n${element}`).join('|||||');
fullResults = fullResults.split(`${element}`).join('|||||');
}
const results = fullResults.split('|||||');

Expand Down Expand Up @@ -152,11 +152,11 @@ export class LlamaCppApiEngine {
targetUser = messages[messages.length - 1].role;
}

// Set {{char}} based on persona.name
// Set {{char}} based on persona.role
// Set {{user}} based on targetUser
// Set {{model}} based on model.name
let description = persona.description;
description = description.replace(/\{\{char\}\}/g, persona.name);
description = description.replace(/\{\{char\}\}/g, persona.role);
description = description.replace(/\{\{user\}\}/g, targetUser);
description = description.replace(/\{\{model\}\}/g, model.name);

Expand All @@ -170,9 +170,9 @@ export class LlamaCppApiEngine {
// Determine how many tokens we have left
usedTokens = calculateTokenLength(systemPrompt);

// Iterate over messagse in reverse order
// Iterate over messages in reverse order
// to generate the chat log
let chatLog = `${promptFormat.userPrepend}${persona.name.toLowerCase()}${promptFormat.userAppend}`;
let chatLog = `${promptFormat.userPrepend}${persona.role.toLowerCase()}${promptFormat.userAppend}`;
for (let i = messages.length - 1; i >= 0; i--) {
const message = messages[i];
let messageLog = '';
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export interface PromptFormat {
// and extensible persona format of our own
// https://github.com/TavernAI/TavernAI/tree/main
export interface Persona {
// Persona name
name: string;
// Persona role
role: string;

// Persona description
description: string;
Expand Down

0 comments on commit 905a4a8

Please sign in to comment.