update spacing to match unified diff format

This commit is contained in:
Nate 2024-09-05 18:15:16 -07:00
parent cc0259e6b3
commit 6eb3f4eb64
5 changed files with 136 additions and 33 deletions

View file

@ -51,7 +51,7 @@ function getMyersDiffType(diff: any): MyersDiffTypes | undefined {
function displayDiff(diff: DiffLine[]) {
const symbol = {
same: " ",
same: "",
new: "+",
old: "-",
};
@ -69,7 +69,7 @@ async function expectDiff(file: string) {
const testFileContents = fs.readFileSync(testFilePath, "utf-8");
const [oldText, newText, expectedDiff] = testFileContents
.split("\n---\n")
.map((s) => s.trim());
.map((s) => s.replace(/^\n+/, "").trimEnd());
const oldLines = oldText.split("\n");
const newLines = newText.split("\n");
const { streamDiffs, myersDiffs } = await collectDiffs(oldLines, newLines);
@ -236,4 +236,8 @@ describe("streamDiff(", () => {
test("FastAPI comments", async () => {
await expectDiff("add-comments");
});
test.skip("Mock LLM example", async () => {
await expectDiff("mock-llm");
});
});

View file

@ -33,21 +33,21 @@ def read_landing_page():
---
+ # Import the FastAPI class from the fastapi module
from fastapi import FastAPI
from fastapi import FastAPI
+ # Create an instance of the FastAPI application
app = FastAPI()
app = FastAPI()
+ # Define a route for the root endpoint ("/")
@app.get("/")
def read_root():
@app.get("/")
def read_root():
+ # Return a simple JSON response
+ return {"Hello": "World"} // This is an example comment
+
+ # Define a route for the landing page endpoint ("/landing")
- return {"Hello": "World"}
-
@app.get("/landing")
def read_landing_page():
@app.get("/landing")
def read_landing_page():
+ # Return a JSON response with a welcome message
return {"message": "Welcome to the landing page"}
return {"message": "Welcome to the landing page"}

View file

@ -28,19 +28,15 @@ def read_landing_page():
- from fastapi import FastAPI
+ from fastapi import FastAPI, HTTPException
app = FastAPI()
@app.get("/")
def read_root():
app = FastAPI()
@app.get("/")
def read_root():
- \treturn {"Hello": "World"}
+ return {"Hello": "World"}
@app.get("/landing")
def read_landing_page():
@app.get("/landing")
def read_landing_page():
+ raise HTTPException(status_code=404, detail="Page not found")
- \treturn {"message": "Welcome to the landing page"}
---
Make sure we correctly ignore tabs-vs-spaces changes
- \treturn {"message": "Welcome to the landing page"}

View file

@ -28,14 +28,14 @@ def read_landing_page():
- from fastapi import FastAPI
+ from fastapi import FastAPI, HTTPException
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/landing")
def read_landing_page():
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/landing")
def read_landing_page():
+ raise HTTPException(status_code=404, detail="Page not found")
- return {"message": "Welcome to the landing page"}

View file

@ -0,0 +1,103 @@
import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js";
import { BaseLLM } from "../index.js";
class Mock extends BaseLLM {
static Completion = "Test Completion";
static providerName: ModelProvider = "mock";
protected async *_streamComplete(
prompt: string,
options: CompletionOptions,
): AsyncGenerator<string> {
yield Mock.Completion;
}
protected async *_streamChat(
messages: ChatMessage[],
options: CompletionOptions,
): AsyncGenerator<ChatMessage> {
yield {
role: "assistant",
content: Mock.Completion,
};
}
}
export default Mock;
---
import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js";
import { BaseLLM } from "../index.js";
class Mock extends BaseLLM {
private static _completion: string = "Test Completion";
static providerName: ModelProvider = "mock";
static get completion(): string {
return Mock._completion;
}
static set completion(value: string) {
Mock._completion = value;
}
protected async *_streamComplete(
prompt: string,
options: CompletionOptions,
): AsyncGenerator<string> {
yield Mock.completion;
}
protected async *_streamChat(
messages: ChatMessage[],
options: CompletionOptions,
): AsyncGenerator<ChatMessage> {
yield {
role: "assistant",
content: Mock.completion,
};
}
}
export default Mock;
---
import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js";
import { BaseLLM } from "../index.js";
class Mock extends BaseLLM {
- static Completion = "Test Completion";
+ private static _completion: string = "Test Completion";
static providerName: ModelProvider = "mock";
+ static get completion(): string {
+ return Mock._completion;
+ }
+
+ static set completion(value: string) {
+ Mock._completion = value;
+ }
+
protected async *_streamComplete(
prompt: string,
options: CompletionOptions,
): AsyncGenerator<string> {
- yield Mock.Completion;
+ yield Mock.completion;
}
protected async *_streamChat(
messages: ChatMessage[],
options: CompletionOptions,
): AsyncGenerator<ChatMessage> {
yield {
role: "assistant",
- content: Mock.Completion,
+ content: Mock.completion,
};
}
}
export default Mock;