Skip to content

Commit b373209

Browse files
fix: type build errors
1 parent bf921af commit b373209

File tree

4 files changed

+56
-41
lines changed

4 files changed

+56
-41
lines changed

src/components/Analysis/MoveMap.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
CartesianGrid,
1010
ResponsiveContainer,
1111
} from 'recharts'
12+
import type { Key } from 'chessground/types'
1213
import type { DrawShape } from 'chessground/draw'
14+
import { ContentType } from 'recharts/types/component/Label'
1315

1416
interface Props {
1517
moveMap?: { move: string; x: number; y: number }[]
@@ -30,8 +32,8 @@ export const MoveMap: React.FC<Props> = ({
3032
}: Props) => {
3133
const onMouseEnter = (move: string) => {
3234
setHoverArrow({
33-
orig: move.slice(0, 2) as any,
34-
dest: move.slice(2, 4) as any,
35+
orig: move.slice(0, 2) as Key,
36+
dest: move.slice(2, 4) as Key,
3537
brush: 'green',
3638
modifiers: {
3739
lineWidth: 10,
@@ -136,22 +138,34 @@ export const MoveMap: React.FC<Props> = ({
136138
position="top"
137139
fontSize={12}
138140
fill="white"
139-
content={({ x, y, value, index }: any) => {
140-
return (
141-
<text
142-
x={x}
143-
y={y}
144-
key={index}
145-
fontSize={12}
146-
textAnchor="middle"
147-
dx={x < 100 ? 24 : 0}
148-
dy={x < 100 ? 0 : y < 55 ? 24 : -5}
149-
fill={colorSanMapping[value].color || '#fff'}
150-
>
151-
{colorSanMapping[value].san}
152-
</text>
153-
)
154-
}}
141+
content={
142+
(({
143+
x,
144+
y,
145+
value,
146+
index,
147+
}: {
148+
x: number
149+
y: number
150+
value: string
151+
index: number
152+
}) => {
153+
return (
154+
<text
155+
x={x}
156+
y={y}
157+
key={index}
158+
fontSize={12}
159+
textAnchor="middle"
160+
dx={x < 100 ? 24 : 0}
161+
dy={x < 100 ? 0 : y < 55 ? 24 : -5}
162+
fill={colorSanMapping[value].color || '#fff'}
163+
>
164+
{colorSanMapping[value].san}
165+
</text>
166+
)
167+
}) as ContentType
168+
}
155169
/>
156170
{moveMap?.map((entry, index) => (
157171
<Cell

src/components/Analysis/MoveRecommendations.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import type { Key } from 'chessground/types'
12
import type { DrawShape } from 'chessground/draw'
3+
24
interface Props {
35
recommendations: {
46
maia?: { move: string; prob: number }[]
@@ -21,8 +23,8 @@ export const MoveRecommendations: React.FC<Props> = ({
2123
}: Props) => {
2224
const onMouseEnter = (move: string) => {
2325
setHoverArrow({
24-
orig: move.slice(0, 2) as any,
25-
dest: move.slice(2, 4) as any,
26+
orig: move.slice(0, 2) as Key,
27+
dest: move.slice(2, 4) as Key,
2628
brush: 'green',
2729
modifiers: {
2830
lineWidth: 10,

src/components/Analysis/MovesByRating.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const MovesByRating: React.FC<Props> = ({
8686
}
8787
return (
8888
<linearGradient
89+
key={`color${move}`}
8990
id={`color${move}`}
9091
x1="0"
9192
y1="0"
@@ -140,7 +141,10 @@ export const MovesByRating: React.FC<Props> = ({
140141
const san = colorSanMapping[point.name as string].san
141142
const prob = Math.round((point.value as number) * 10) / 10
142143
return (
143-
<div className="flex items-center justify-between px-3">
144+
<div
145+
key={san}
146+
className="flex items-center justify-between px-3"
147+
>
144148
<p
145149
style={{
146150
color:

src/utils/maia2/model.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import * as ort from 'onnxruntime-web'
1+
import { InferenceSession, Tensor } from 'onnxruntime-web'
22

33
import { mirrorMove, preprocess, allPossibleMovesReversed } from './utils'
44

55
class Maia {
6-
public model!: ort.InferenceSession
6+
public model!: InferenceSession
77
public ready: boolean
88

99
constructor(options: { model: string }) {
1010
this.ready = false
1111
;(async () => {
1212
try {
1313
const buffer = await this.getCachedModel(options.model)
14-
this.model = await ort.InferenceSession.create(buffer)
14+
this.model = await InferenceSession.create(buffer)
1515

1616
this.ready = true
1717
} catch (e) {
@@ -49,13 +49,13 @@ class Maia {
4949
preprocess(board, eloSelf, eloOppo)
5050

5151
// Load and run the model
52-
const feeds: Record<string, ort.Tensor> = {
53-
boards: new ort.Tensor('float32', boardInput, [1, 18, 8, 8]),
54-
elo_self: new ort.Tensor(
52+
const feeds: Record<string, Tensor> = {
53+
boards: new Tensor('float32', boardInput, [1, 18, 8, 8]),
54+
elo_self: new Tensor(
5555
'int64',
5656
BigInt64Array.from([BigInt(eloSelfCategory)]),
5757
),
58-
elo_oppo: new ort.Tensor(
58+
elo_oppo: new Tensor(
5959
'int64',
6060
BigInt64Array.from([BigInt(eloOppoCategory)]),
6161
),
@@ -113,19 +113,14 @@ class Maia {
113113
combinedBoardInputs.set(boardInputs[i], i * 18 * 8 * 8)
114114
}
115115

116-
const feeds: Record<string, ort.Tensor> = {
117-
boards: new ort.Tensor('float32', combinedBoardInputs, [
118-
batchSize,
119-
18,
120-
8,
121-
8,
122-
]),
123-
elo_self: new ort.Tensor(
116+
const feeds: Record<string, Tensor> = {
117+
boards: new Tensor('float32', combinedBoardInputs, [batchSize, 18, 8, 8]),
118+
elo_self: new Tensor(
124119
'int64',
125120
BigInt64Array.from(eloSelfCategories.map(BigInt)),
126121
[batchSize],
127122
),
128-
elo_oppo: new ort.Tensor(
123+
elo_oppo: new Tensor(
129124
'int64',
130125
BigInt64Array.from(eloOppoCategories.map(BigInt)),
131126
[batchSize],
@@ -147,11 +142,11 @@ class Maia {
147142
startIdx,
148143
endIdx,
149144
) as Float32Array
150-
const policyTensor = new ort.Tensor('float32', policyLogitsArray, [
145+
const policyTensor = new Tensor('float32', policyLogitsArray, [
151146
logitsPerItem,
152147
])
153148
const valueLogit = logits_value.data[i] as number
154-
const valueTensor = new ort.Tensor('float32', [valueLogit], [1])
149+
const valueTensor = new Tensor('float32', [valueLogit], [1])
155150

156151
const { policy, value: winProb } = processOutputs(
157152
boards[i],
@@ -181,8 +176,8 @@ class Maia {
181176
*/
182177
function processOutputs(
183178
fen: string,
184-
logits_maia: ort.Tensor,
185-
logits_value: ort.Tensor,
179+
logits_maia: Tensor,
180+
logits_value: Tensor,
186181
legalMoves: Float32Array,
187182
) {
188183
const logits = logits_maia.data as Float32Array

0 commit comments

Comments
 (0)